I have a data-frame which looks as follows,
head(elnino)
YEAR..MONTH NINO.3 NINO.3.4 rainfall
1 1950 Jan -1.28 -1.34 5.8
2 1950 Feb -1.10 -1.25 17.8
3 1950 Mar -0.92 -1.16 22.4
4 1950 Apr -0.75 -1.01 8.0
5 1950 May -0.47 -0.75 44.0
6 1950 Jun -0.49 -0.74 146.8
Now the First column ie, YEAR..MONTH is of class FACTOR. I want to convert it to class yearmon. But i am getting NA's as shown below,
as.yearmon(elnino[,1], "%Y-%m")
NA
Moreover ggplot doesn't support yearmon class while plotting.
Therefore can someone please tell me how to handle date of this type?
The data is as follows,
dput(head(elnino))
structure(list(YEAR..MONTH = c("1950 Jan", "1950 Feb", "1950 Mar",
"1950 Apr", "1950 May", "1950 Jun"), NINO.3.ANOM = c(-1.28,
-1.1, -0.92, -0.75, -0.47, -0.49), NINO.3.4.ANOM = c(-1.34, -1.25,
-1.16, -1.01, -0.75, -0.74), rainfall = c(5.8, 17.8, 22.4, 8,
44, 146.8)), .Names = c("YEAR..MONTH", "NINO.3.ANOM", "NINO.3.4.ANOM",
"rainfall"), row.names = c(NA, 6L), class = "data.frame")
Moreover the error i get while plotting yearmon class objects with ggplot is as follows,
qplot(YEAR..MONTH,rainfall,data = elnino,geom="line")
Don't know how to automatically pick scale for object of type yearmon. Defaulting to continuous
Error: Discrete value supplied to continuous scale