[R] read.csv() error

Enrico Schumann e@ @end|ng |rom enr|co@chum@nn@net
Thu Sep 2 18:43:22 CEST 2021


On Thu, 02 Sep 2021, Rich Shepard writes:

> The first three commands in the script are:
> stage <- read.csv('../data/water/gauge-ht.dat', header
> = TRUE, sep = ',', stringsAsFactors = FALSE)
> stage$sampdate <- as.Date(stage$sampdate)
> stage$ht <- as.numeric(stage$ht, length = 6)
>
> Running the script produces this error:
>> source('stage.R')
> Error in `$<-.data.frame`(`*tmp*`, ht, value = numeric(0)) :
>   replacement has 0 rows, data has 486336
>
> Sample lines from the data file:
> sampdate,samptime,elev
> 2007-10-01,01:00,2.80
> 2007-10-01,01:15,2.71
> 2007-10-01,01:30,2.63
> 2007-10-01,01:45,2.53
> 2007-10-01,02:00,2.45
> 2007-10-01,02:15,2.36
> 2007-10-01,02:30,2.27
> 2007-10-01,02:45,2.17
> 2007-10-01,03:00,2.07
>
> Maximum value for elev is about 11.00, 5 digits.
>
> I don't understand this error because the equivalent commands for another
> data source file completes without error.
>
> What is that error message telling me?
>
> TIA,
>
> Rich
>

There is no column 'ht'.

-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net



More information about the R-help mailing list