The error tells you exactly what is wrong:
test <- read.table(text="Date Subject val1 val2 val3
2010-05-01 12 -0.6155 0.5083 2.6286
2010-06-03 13 0.96416 0.785 1.41
2010-07-01 14 0.9578 1.258 0.579
2010-08-01 15 1.249 1.879 0.268",header=TRUE)
> str(test$Date)
Factor w/ 4 levels "2010-05-01","2010-06-03",..: 1 2 3 4
See the Factor w/ 4 levels
? You need a Date
instead.
Try:
test$Date <- as.Date(test$Date)
Now:
> str(test$Date)
Date[1:4], format: "2010-05-01" "2010-06-03" "2010-07-01" "2010-08-01"
Alternatively you can specify you want a Date
output for the specific variable when reading in the csv using the colClasses
option:
test <- read.csv(
filename.csv,
header=TRUE,
colClasses=c(Date="Date")
)