如果我想将字符串转换为 POSIXlt 会出现问题,但我无法弄清楚问题所在。
df<-data.frame(a=c("2013-07-01 11:51:03" ,"2013-07-01 12:01:50", "2013-07-01 12:05:13"),b=1:3)
#factor(df[,"a"])
df[,"a"]<-as.POSIXlt(as.character(df[,"a"]),origin = "1960-01-01",tz="GMT")
> Warning message:
In `[<-.data.frame`(`*tmp*`, , "a", value = list(sec = c(3, 50, :
9 variables declared, to replace 1 variablen
df<-data.frame(a=c("2013-07-01 11:51:03" ,"2013-07-01 12:01:50", "2013-07-01 12:05:13"),b=1:3)
df$a<-as.POSIXlt(as.character(df[,"a"]),origin = "1960-01-01",tz="GMT")
factor(df[,"a"])
> Error in sort.list(y) : 'x' should be atomar for 'sort.list'
直到现在我使用了一个解决方法
a<-as.POSIXlt(as.character(df[,"a"]),origin = "1960-01-01",tz="GMT")
df1<-data.frame(a,df[,"b"])