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.

462 questions
125
votes
15 answers

'Incomplete final line' warning when trying to read a .csv file into R

I'm trying to read a .csv file into R and upon using this formula: pheasant<-read.table(file.choose(),header=TRUE,sep=",") I get this warning message: "incomplete final line found by readTableHeader on 'C:\Documents and Settings..." There are a…
Kate
  • 1,261
  • 2
  • 10
  • 4
116
votes
7 answers

Specifying colClasses in the read.csv

I am trying to specify the colClasses options in the read.csv function in R. In my data, the first column "time" is basically a character vector while the rest of the columns are numeric. data <- read.csv("test.csv", comment.char="" , …
defoo
  • 4,659
  • 11
  • 30
  • 38
106
votes
4 answers

Specify custom Date format for colClasses argument in read.table/read.csv

Question: Is there a way to specify the Date format when using the colClasses argument in read.table/read.csv? (I realise I can convert after importing, but with many date columns like this, it would be easier to do it in the import…
Tommy O'Dell
  • 6,553
  • 13
  • 51
  • 67
83
votes
6 answers

Is there a way to use read.csv to read from a string value rather than a file in R?

I'm writing an R package where the R code talks to a Java application. The Java application outputs a CSV formatted string and I want the R code to be able to directly read the string and convert it into a data.frame.
tommy chheng
  • 8,680
  • 9
  • 53
  • 69
72
votes
8 answers

Imported a csv-dataset to R but the values becomes factors

I am very new to R and I am having trouble accessing a dataset I've imported. I'm using RStudio and used the Import Dataset function when importing my csv-file and pasted the line from the console-window to the source-window. The code looks as…
Joe
  • 943
  • 2
  • 7
  • 6
66
votes
5 answers

Why am I getting X. in my column names when reading a data frame?

I asked a question about this a few months back, and I thought the answer had solved my problem, but I ran into the problem again and the solution didn't work for me. I'm importing a CSV: orders <- read.csv("", sep=",", header=T,…
mikebmassey
  • 7,126
  • 23
  • 62
  • 88
57
votes
6 answers

How to detect the right encoding for read.csv?

I have this file (http://b7hq6v.alterupload.com/en/) that I want to read in R with read.csv. But I am not able to detect the correct encoding. It seems to be a kind of UTF-8. I am using R 2.12.1 on an WindowsXP Machine. Any Help?
Alex
  • 849
  • 1
  • 7
  • 12
54
votes
1 answer

Difference between read.csv() and read.csv2() in R

In R , what is the difference between read.csv() and read.csv2() The official documentation says, In various European locales, as the comma character serves as the decimal point, the function read.csv2 should be used instead What does this…
Anoop
  • 4,820
  • 7
  • 33
  • 47
48
votes
9 answers

Invalid multibyte string in read.csv

I am trying to import a csv that is in Japanese. This code: url <- 'http://www.mof.go.jp/international_policy/reference/itn_transactions_in_securities/week.csv' x <- read.csv(url, header=FALSE, stringsAsFactors=FALSE) returns the following…
jaredwoodard
  • 677
  • 1
  • 6
  • 8
31
votes
3 answers

read.csv, header on first line, skip second line

I have a CSV file with two header rows, the first row I want to be the header, but the second row I want to discard. If I do the following command: data <- read.csv("HK Stocks bbg.csv", header = T, stringsAsFactors = FALSE) The first row becomes…
mchangun
  • 8,274
  • 18
  • 64
  • 94
28
votes
5 answers

How can I read the header but also skip lines - read.table()?

Data.txt: Index;Time; 1;2345; 2;1423; 3;5123; The code: dat <- read.table('data.txt', skip = 1, nrows = 2, header =TRUE, sep =';') The result: X1 X2345 1 2 1423 2 3 5123 I expect the header to be Index and Time, as follows: Index Time 1 …
hans-t
  • 2,607
  • 5
  • 25
  • 36
27
votes
2 answers

Skip specific rows using read.csv in R

I wish to skip the 1st and 3rd rows of my csv file when importing the file into a data frame in R. In the original file my headers are on line 2. Using the skip argument in read.csv I can skip the 1st line and set the header argument to TRUE by I…
TheGoat
  • 1,765
  • 2
  • 16
  • 40
25
votes
4 answers

read.csv blank fields to NA

I have tab delimited text file, named 'a.txt'. The D column is empty. A B C D 10 20 NaN 30 40 40 30 20 20 NA 20 I want to have the dataframe looking and acting exactly as the text file, with…
user1631306
  • 3,844
  • 8
  • 30
  • 65
23
votes
5 answers

How to read only lines that fulfil a condition from a csv into R?

I am trying to read a large csv file into R. I only want to read and work with some of the rows that fulfil a particular condition (e.g. Variable2 >= 3). This is a much smaller dataset. I want to read these lines directly into a dataframe, rather…
Hernan
  • 371
  • 1
  • 2
  • 8
22
votes
4 answers

Avoid that space in column name is replaced with period (".") when using read.csv()

I am using R to do some data pre-processing, and here is the problem that I am faced with: I input the data using read.csv(filename,header=TRUE), and then the space in variable names became ".", for example, a variable named Full Code became…
zeno tsang
  • 705
  • 1
  • 6
  • 15
1
2 3
30 31