I am reading a .xlsx file using R. One of the columns is called "Date" and it has the following format: "20/10/2014 12:00:00 am".
我正在使用R读取.xlsx文件。其中一列称为“日期”,它具有以下格式:“20/10/2014 12:00:00 am”。
However, when I read the file using R's xlsx
package, the value becomes 41932-- class factor
. How can I read the entire column as a string (as is)? I want to be the one to convert the date/time values into POSIXlt
and/or POSIXct
classes.
但是,当我使用R的xlsx包读取文件时,该值变为41932--类因子。如何将整个列作为字符串读取(按原样)?我想成为将日期/时间值转换为POSIXlt和/或POSIXct类的人。
1 个解决方案
#1
You can read into string with Hadley's readxl
package.
您可以使用Hadley的readxl包读入字符串。
library(readxl)
df <- read_excel('~/Desktop/test.xlsx')
There is some support for col_type
but it's not ready yet. Instead, you can use as.POSIXct
to fix those after being read into a data.frame
对col_type有一些支持,但还没有准备好。相反,您可以使用as.POSIXct在读入data.frame后修复它们
e.g.
as.POSIXct(df$Date, format="%d/%m/%Y %H:%M:%S", tz="CET")
#1
You can read into string with Hadley's readxl
package.
您可以使用Hadley的readxl包读入字符串。
library(readxl)
df <- read_excel('~/Desktop/test.xlsx')
There is some support for col_type
but it's not ready yet. Instead, you can use as.POSIXct
to fix those after being read into a data.frame
对col_type有一些支持,但还没有准备好。相反,您可以使用as.POSIXct在读入data.frame后修复它们
e.g.
as.POSIXct(df$Date, format="%d/%m/%Y %H:%M:%S", tz="CET")