[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,15 2,2000,20 3,,30 4,3500,35 5,4000,45 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@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.
Re: [R] Way of handling empty value when reading in CSV
I saved your data as test.csv, and read.csv(~/test.csv, header = TRUE) home sqr_footage cost 111500 15 222000 20 33 NA 30 443500 35 554000 45 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-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jason Rupert Sent: Tuesday, October 06, 2009 11:39 AM To: R-help@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,15 2,2000,20 3,,30 4,3500,35 5,4000,45 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@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. __ R-help@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.
Re: [R] Way of handling empty value when reading in CSV
Well, I guess I posted a poor example. This example is a little closer: home,sqr_footage,cost,color,exterior 1,1500,15,,Siding 2,2000,20,Red,Brick 3,,30,Grey,Brick 4,3500,35,Blue, 5,4000,45,Red,Brick This one actually shows the presence of the null fields that are loaded. Sorry again for the poor 1st example. Thank you again for your time and insight. --- On Tue, 10/6/09, Erik Iverson eiver...@nmdp.org wrote: From: Erik Iverson eiver...@nmdp.org Subject: RE: [R] Way of handling empty value when reading in CSV To: Jason Rupert jasonkrup...@yahoo.com, R-help@r-project.org R-help@r-project.org Date: Tuesday, October 6, 2009, 11:42 AM I saved your data as test.csv, and read.csv(~/test.csv, header = TRUE) home sqr_footage cost 1 1 1500 15 2 2 2000 20 3 3 NA 30 4 4 3500 35 5 5 4000 45 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-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jason Rupert Sent: Tuesday, October 06, 2009 11:39 AM To: R-help@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,15 2,2000,20 3,,30 4,3500,35 5,4000,45 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@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. __ R-help@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.
Re: [R] Way of handling empty value when reading in CSV
Does this do what you want: ) x - read.csv(textConnection(home,sqr_footage,cost,color,exterior + 1,1500,15,,Siding + 2,2000,20,Red,Brick + 3,,30,Grey,Brick + 4,3500,35,Blue, + 5,4000,45,Red,Brick), na.strings='') closeAllConnections() x home sqr_footage cost color exterior 111500 15 NA Siding 222000 20 RedBrick 33 NA 30 GreyBrick 443500 35 Blue NA 554000 45 RedBrick On Tue, Oct 6, 2009 at 1:12 PM, Jason Rupert jasonkrup...@yahoo.com wrote: Well, I guess I posted a poor example. This example is a little closer: home,sqr_footage,cost,color,exterior 1,1500,15,,Siding 2,2000,20,Red,Brick 3,,30,Grey,Brick 4,3500,35,Blue, 5,4000,45,Red,Brick This one actually shows the presence of the null fields that are loaded. Sorry again for the poor 1st example. Thank you again for your time and insight. --- On Tue, 10/6/09, Erik Iverson eiver...@nmdp.org wrote: From: Erik Iverson eiver...@nmdp.org Subject: RE: [R] Way of handling empty value when reading in CSV To: Jason Rupert jasonkrup...@yahoo.com, R-help@r-project.org R-help@r-project.org Date: Tuesday, October 6, 2009, 11:42 AM I saved your data as test.csv, and read.csv(~/test.csv, header = TRUE) home sqr_footage cost 1 1 1500 15 2 2 2000 20 3 3 NA 30 4 4 3500 35 5 5 4000 45 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-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jason Rupert Sent: Tuesday, October 06, 2009 11:39 AM To: R-help@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,15 2,2000,20 3,,30 4,3500,35 5,4000,45 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@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. __ R-help@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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@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.