如何将系数转换为R中的DateTime? [英] how to convert factor into DateTime in R?
问题描述
这个问题对于一些人来说可能很简单,但是因为我是R的初学者,而是忍受我。
This question might be simple for some of you but bear with me since I'm a beginner in R.
我有一个数据框,它有一个因子列称为时间)包含DateTime数据如下:
I have a dataframe that has a factor column (called time) containing DateTime data as the following:
time
01/01/2011 00:10
02/01/2011 03:00
03/01/2011 05:00
04/01/2011 10:03
我想将此列转换为R中的DateTime列。我搜索并尝试了一些功能,但它给出了NA结果。以下功能是我尝试过的功能:
I want to convert this column into DateTime column in R. I searched and tried some functions but it gives me 'NA' results. The following functions are those I tried:
> dataframe1$datetime <- as.POSIXlt(as.character(dataframe1$time), format="%d/%m/%Y %H:%M")
> dataframe1$datetime <- as.POSIXlt(strptime(dataframe1$time), format="%d/%m/%Y %H:%M")
> dataframe1$datetime <- as.POSIXlt(dataframe1$time, format="%d/%m/%Y %H:%M")
> dataframe1$datetime <- as.chron(dataframe1$time, "%d/%m/%Y %H:%M")
我不知道还有什么要尝试的。我希望理想地添加三列,即日期时间,日期和时间。非常感谢您的帮助。
I don't know what else to try. I want ideally to add three columns namely datetime, date, and time. Your help is much appreciated.
非常感谢advacne。
Many thanks in advacne.
推荐答案
尝试:
dataframe1$datetime <- strptime(x = as.character(dataframe1$datetime),
format = "%d/%m/%Y %H:%M")
这篇关于如何将系数转换为R中的DateTime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!