[R] Way of handling empty value when reading in CSV

Erik Iverson eiverson at NMDP.ORG
Tue Oct 6 18:42:41 CEST 2009


I saved your data as test.csv, and 

> read.csv("~/test.csv", header = TRUE)
  home sqr_footage   cost
1    1        1500 150000
2    2        2000 200000
3    3          NA 300000
4    4        3500 350000
5    5        4000 450000

I am using R 2.8.1, old I know... but maybe something else is going on?  Do you really get a blank when you read in your sample data? 

Erik 

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Jason Rupert
> Sent: Tuesday, October 06, 2009 11:39 AM
> To: R-help at r-project.org
> Subject: [R] Way of handling empty value when reading in CSV
> 
> I believe I may be overlooking something simple in order address this, but
> I have searched RSeek.org and using "?", but cannot seem to find anything
> discussing this one.
> 
> 
> I am using read.csv to read in a csv file.  Evidently in places there is
> nothing between the commas, so that when the data is read in the
> data.frame produced has values that are empty.
> 
> 
> Is there a way to fix this when reading the data via "read.csv"?  I looked
> at all the options mentioned in ?read.csv, but did not see anything to
> address this case, e.g.
> 
> 
> home,sqr_footage,cost
> 1,1500,150000
> 2,2000,200000
> 3,,300000
> 4,3500,350000
> 5,4000,450000
> 
> 
> I would like for the empty cells to have a value of "NA" when they are
> read in.
> 
> 
> Thank you for any feedback and insights.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list