Convert string to date in sparkR

白昼怎懂夜的黑 提交于 2019-12-08 06:42:47

问题


I have this data.frame in sparkR

df <- data.frame(user_id=c(1,1,2,2),
             time=c("2015-7-10","2015-8-04","2015-8-8","2015-7-10"))

I make this to a DataFrame

dft <- createDataFrame(sqlContext, df)

I want to convert the date (which is now a string) to a 'date'-type. I use the 'cast'-function

dft$time <- cast(dft$time, 'date')

But now when I use head(dft) I can see that 'time' only contain NA.

Maybe there should be added something to the 'cast'-function or maybe there should be loaded a package before using it? Alternative one could use 'as.Date' on the data.frame but it takes time for large data.

I have the exact same problem with 'integer'. If I type

cast(dft$time, 'int')

time will then produce NA.

来源:https://stackoverflow.com/questions/32046120/convert-string-to-date-in-sparkr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!