[R] Understanding read.csv error message
peter dalgaard
pd@|gd @end|ng |rom gm@||@com
Sat Aug 18 11:05:52 CEST 2018
What Don said, and also notice that the error is not about anything having value 0, it is about replacing something with something of _length_ 0. It is not obvious where that happens, sometimes a traceback() can give a clue, but probably Don is right that the issue is that there is something not quite CSV in the file.
One further idea is to read using colClasses="character" and see if that actually gives you 6 columns and then afterwards try and convert each column to the appropriate type.
-pd
> On 18 Aug 2018, at 00:08 , Rich Shepard <rshepard using appl-ecosys.com> wrote:
>
> I have a data file, 'precip_projected.csv,' that starts like this:
>
> name,easting,northing,elev,sampdate,prcp
> Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-01,0.59
> Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-02,0.08
> Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-03,0.1
> Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-04,0
> Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-05,0
> Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-06,0.02
> Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-07,0.05
> Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-08,0.1
> Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-09,0
> Headworks Portland Water,2370575.38427211,199337.634652112,228,2005-01-10,0.02
>
> There are a bunch of NAs in the data file.
>
> The command to read it produces an error:
>
> rainfall <- read.csv('../data/precipitation/precip_projected.csv', header = T, sep = ',', as.is = T)
>
> Error in `$<-.data.frame`(`*tmp*`, date, value = numeric(0)) :
> replacement has 0 rows, data has 113569
>
> Is the error generated by finding a date that looks like the number zero
> or by a prcp value of zero?
>
> BTW, I get the same error if I specify stringsAsFactors = F.
>
> TIA,
>
> Rich
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes using cbs.dk Priv: PDalgd using gmail.com
More information about the R-help
mailing list