[R] read.table() question
Rich Shepard
rshepard at appl-ecosys.com
Wed Oct 19 22:54:04 CEST 2016
The file, daily_records.dat, contains these data:
"station","date","amount"
"0.3E",2014-01-01,
"0.3E",2014-01-02,
"0.3E",2014-01-03,0.01
"0.3E",2014-01-04,0.00
"0.3E",2014-01-05,0.00
"0.3E",2014-01-06,0.00
"0.3E",2014-01-07,0.10
"0.3E",2014-01-08,0.22
"0.3E",2014-01-09,0.49
Using read.table("daily_records.dat", header = TRUE, sep = ",", quote =
"\"\"") the data are assigned to a data.frame named 'rain.'
I expect the structure to show station and date as factors with amount as
numeric, but they're all factors:
str(rain)
'data.frame': 341 obs. of 3 variables:
$ station: Factor w/ 6 levels "0.3E","0.6W",..: 1 1 ...
$ date : Factor w/ 62 levels "2013-12-01","2013-12-02",..: 32 33 34 ...
$ amount : Factor w/ 48 levels "","0.00","0.01",..: 1 1 3 2 ...
Why is amount taken as a factor rather than numeric? I do not recall
having numbers read as factors before this.
I expect to need to convert dates using as.Date() but not to convert
numbers.
TIA,
Rich
More information about the R-help
mailing list