Re: [R] read.csv() error

2021-09-02 Thread Rich Shepard

On Thu, 2 Sep 2021, Enrico Schumann wrote:


There is no column 'ht'.


Enrico,

New eyeballs caught my change in variable name that I kept missing.

Thanks very much,

Rich

__
R-help@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.


Re: [R] read.csv() error

2021-09-02 Thread Enrico Schumann
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
>

(Sorry, sent too early.)

There is no column 'ht'.

df <- data.frame(a = 1:5)
df$b <- as.numeric(df$b)
## Error in `$<-.data.frame`(`*tmp*`, b, value = numeric(0)) : 
##   replacement has 0 rows, data has 5

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

__
R-help@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.


Re: [R] read.csv() error

2021-09-02 Thread Enrico Schumann
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

__
R-help@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.


Re: [R] read.csv error: invalid multibyte string

2012-02-19 Thread Milan Bouchet-Valat
Le samedi 31 décembre 2011 à 07:05 -0800, Dennis Fisher a écrit :
 R version: 2.13.1
 OS X
 
 Colleagues,
 
 I am working with a CSV file; for testing purposes, I created an XLS version 
 of the file.  
 When I read these files using read.xls (gdata) or read.csv, I encounter an 
 error:
   Error in type.convert(data[[i]], as.is = as.is[i], dec = dec, 
 na.strings = character(0L)) : 
 invalid multibyte string at 'b0C'
 The error occurs whether or not I invoke the as.is option of read.csv.
Please provide the output of sessionInfo(). I know that on OS X JGR
often (always?) gets the locale wrong, which leads to bugs when
importing any non-ASCII character strings. That's maybe what you're
experiencing. Have you tried with the default R GUI?


Hope this helps

__
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] read.csv error: invalid multibyte string

2011-12-31 Thread peter dalgaard

On Dec 31, 2011, at 16:05 , Dennis Fisher wrote:

 R version: 2.13.1
 OS X
 
 Colleagues,
 
 I am working with a CSV file; for testing purposes, I created an XLS version 
 of the file.  
 When I read these files using read.xls (gdata) or read.csv, I encounter an 
 error:
   Error in type.convert(data[[i]], as.is = as.is[i], dec = dec, 
 na.strings = character(0L)) : 
 invalid multibyte string at 'b0C'
 The error occurs whether or not I invoke the as.is option of read.csv.
 
 The trigger for this error is a degree C string (\xb0).  The offending line 
 is:
 [1] 
 \DD4A14\,\VITALS\,\SITE038\,\038-501\,\SCREENING\,\\,\Temperature\,\37.8\,\\xb0C\,\1005_TS\,\e2\,\1005/cla\,\\,5/25/2011,-1,2,0,0,0,0,0,0,1,7/20/2011
  16:48:25,240,1

I think this means that you are working in UTF-8, trying to read something that 
is encoded in Latin-1. Try playing with the fileEncoding or encoding arguments; 
my first try would be fileEncoding=latin1.

-pd


 
 I can get around the error by reading the file with readLines, then editing 
 out that character:
   PATH - textConnection(sub(\xb0, degrees, readLines(PATH)))
   read.csv(PATH, header=T, as.is=T) 
 This alternate approach is successful.  This leads to two questions:
 
 1.  Why can readLines handle that character string whereas read.csv cannot?
 
 2.  Reading the text connection is slow -  it takes ~ 11 seconds to read a 
 file with 11K rows.  I edited the file to replace to offending character with 
 degree.  read.csv reads the 11K rows of the new file in a fraction of a 
 second. Can someone explain why reading the text connection is so much slower 
 than reading a file?
 
 Dennis
 
 Dennis Fisher MD
 P  (The P Less Than Company)
 Phone: 1-866-PLessThan (1-866-753-7784)
 Fax: 1-866-PLessThan (1-866-753-7784)
 www.PLessThan.com
 
 __
 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
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.