Revisiting invalid type (list) for variable X, where X is the date class
Earlier today I followed the following thread and saw his answer: Invalid type (list) for variable X, where X is the date class , but the answer did not work for me!
The poster posted the following data
Values;Date.Col
911;20/12/2013 04:05:01 p.m.
124,82;23/12/2013 09:43:03 a.m.
287;23/12/2013 09:44:15 a.m.
37,3;23/12/2013 09:45:26 a.m.
448,4;23/12/2013 09:46:50 a.m.
432,5;23/12/2013 09:48:31 a.m.
I copied the data into gedit and saved it as tmp.csv.
Then I applied the response code from the original post,
df <- read.table("tmp.csv", header = T, dec = ',', sep = ';')
df$Date.Col <- as.POSIXct(df$Date.Col, format = "%d/%m/%Y %I:%M:%S %p")
plot(Values ~ Date.Col, df[-1,], type = 'l')
But it just comes back
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
Why does this work for the original poster but not for me?
Other comments, when I run the first line of code then str (df) I get
str(df)
'data.frame': 6 obs. of 2 variables:
$ Values : num 911 124.8 287 37.3 448.4 ...
$ Date.Col: Factor w/ 6 levels "20/12/2013 04:05:01 p.m.",..: 1 2 3 4 5 6
Of course strAsAsFactors = FALSE gets rid of the factors, but the code still doesn't work (the second line fills in df $ Date.Col with NA values.
source to share
Thanks to @MrFlick, I have an answer to the question. He explains that the% p format is locale specific. To get the code to work, I needed to strip my data by removing the periods from am.m to give am and pm until evening (which I did manually).
Values;Date.Col
911;20/12/2013 04:05:01 pm
124,82;23/12/2013 09:43:03 am
287;23/12/2013 09:44:15 am
37,3;23/12/2013 09:45:26 am
448,4;23/12/2013 09:46:50 am
432,5;23/12/2013 09:48:31 am
I saved the data as described above and used the same code that worked this time. (See comments above for more details).
ps question answered by myself to close it.
source to share