Questions tagged [read.csv]

The command in R to read a data file with a “comma separated values” (csv) format.

The read.csv is a command in R to read a data file with a “comma separated values” (csv) format.

737 questions
7
votes
1 answer

R read.csv how to ignore carriage return?

I need to read a text file (tab-separated) that has some carriage returns inside some fields. If I use read.table, it gives me an error: line 6257 did not have 20 elements If I use read.csv, it doesn't give an error, but creates a new line in that…
Rodrigo
  • 4,706
  • 6
  • 51
  • 94
7
votes
2 answers

read.csv Read Specific Row

How can we read specific rows into R using the read.csv command? Say if I have a CSV file which has 10 rows of data, and I just want to only read the 5th row of data, I tried doing the following but it doesn't seem to be working: myFile <-…
Outrigger
  • 149
  • 1
  • 3
  • 10
7
votes
4 answers

Read.CSV not working as expected in R

I am stumped. Normally, read.csv works as expected, but I have come across an issue where the behavior is unexpected. It most likely is user error on my part, but any help will be appreciated. Here is the URL for the…
Btibert3
  • 38,798
  • 44
  • 129
  • 168
6
votes
1 answer

Skipping specific rows and columns in R

I skipped second row of the data using this command: Df=(read.csv(“IMDB_data.csv”, header=T, sep=",")[-2,]) What is the explanation behind this? Can it be used for skipping more than 1 specific row? Can it used for skipping columns? Please help.
user9716225
  • 63
  • 1
  • 1
  • 4
6
votes
2 answers

How to check if CSV file has a comma or a semicolon as separator?

I have to read in a lot of CSV files automatically. Some have a comma as a delimiter, then I use the command read.csv(). Some have a semicolon as a delimiter, then I use read.csv2(). I want to write a piece of code that recognizes if the CSV file…
ValentinDarting
  • 117
  • 2
  • 11
6
votes
3 answers

read.csv replaces column-name characters like `?` with `.`, `-` with `...`

I'm using RStudio and my output on the Console gets truncated. I can't find how to stop the truncation (I tried searching ?options as well as googling around for longer than I'd like to admit). EDIT: My apologies everyone! I originally had the…
Will
  • 11,276
  • 9
  • 68
  • 76
6
votes
3 answers

Skip all leading empty lines in read.csv

I am wishing to import csv files into R, with the first non empty line supplying the name of data frame columns. I know that you can supply the skip = 0 argument to specify which line to read first. However, the row number of the first non empty…
Alex
  • 15,186
  • 15
  • 73
  • 127
5
votes
4 answers

Skipping last column in r with read.csv

I was on that post read.csv and skip last column in R but did not find my answer, and try to check directly in Answer ... but that's not the right way (thanks mjuarez for taking the time to get me back on track. The original question was: I have…
5
votes
2 answers

Merge multiple .csv files into one

I am aware this question has been asked multiple times, but despite of trying to apply the aforementioned solutions i was not able to solve my little problem: I have saved all my .csv that i am aiming to merge into one folder: > file_list <-…
Nneka
  • 1,764
  • 2
  • 15
  • 39
5
votes
1 answer

Dealing with Byte Order Mark (BOM) in R

Sometimes a Byte Order Mark (BOM) is present at the beginning of a .CSV file. The symbol is not visible when you open the file using Notepad or Excel, however, When you read the file in R using various methods, you will different symbols in the name…
Gaurav Singhal
  • 998
  • 2
  • 10
  • 25
5
votes
1 answer

Using read.csv with a symlinked file

What I Am Trying To Do My source file is very large and I want to avoid copying it into other folders. I decided to create a symlink to the large file and want to use read.csv to read in the file. Folder…
sharly
  • 237
  • 2
  • 7
5
votes
0 answers

R dates automatically detected when reading in .csv files?

I have a chunk of code that I regularly run to read in and clean up a.csv file. Part of the clean up process is to identify date columns and convert them to the correct format, which I do with a function (see below). I set the date format to…
Amy M
  • 967
  • 1
  • 9
  • 19
5
votes
3 answers

Error in file(file, "rt") : cannot open the connection - cannot open file 'specdata' access denied

I'm running rStudio v3.1.2 on Windows 7. This laptop is a 64-bit machine. I'm taking the JHU R Programming course offered by Coursera and am stuck on an error I'm receiving in part 1 of the problem. I have some error handling functions I'm keeping…
ASwiftPeregrine
  • 131
  • 1
  • 1
  • 12
5
votes
1 answer

Insert NA values into dataframe blank cells when importing read.csv/read.xlsx

The attached screenshot shows part of a dataframe which I have just imported into R from an excel file. In the cells which are blank, I need to insert 'NA'. How can I insert NA into any cell which is blank (whilst leaving the already populated cells…
luciano
  • 13,158
  • 36
  • 90
  • 130
4
votes
1 answer

read.csv() - two out of three columns

Possible Duplicate: Only read limited number of columns in R I have a ascii-dataset which consists of three columns, but only the last two are actual data. Now I want to dotchart the data by using read.csv(file = "result1", sep= " "). R reads all…
user2442121
1 2
3
49 50