damnguychen
damnguychen

Reputation: 21

Read.csv: some rows are missing

I use:

read.csv('....csv', as.is=TRUE, header=TRUE)

There is a header in the first row and without that row there are still 72139 rows but I can only read 72138 rows. And I cannot figure out why R automatically omits a row.

I checked the first few rows and there is no problem with them.

Updated: I tried another similar csv and R missed more than 10000 row......then i found my answer here...read.csv in R doesn't import all rows from csv file

I use quote="" in my read.csv() but then you have to be careful with your character variables.

I am still curious since some other csv files also have double quote but with fewer rows(approximately 30000) but I never had any mistake with them before...can anyone help me with this question?

thanks

Upvotes: 2

Views: 2196

Answers (2)

Gabriela Alberola
Gabriela Alberola

Reputation: 11

I had the same issue with a dataset of 50,000 rows, with only about half importing using read.csv.None of the suggestions here and in other forums worked for me. What solved it immediately was a suggestion from my advisor to use read_csv instead, from the "readr" package. Here are instructions: https://readr.tidyverse.org/

Upvotes: 1

seven7e
seven7e

Reputation: 818

How do you count the rows in the file? wc -l? If there is one blank row (most possibly in the last of file), wc will include it also.

If not, you can write the dataframe out with write.csv and compare the result with original data file using something like diff to see which row is missing.

Upvotes: 1

Related Questions