将每个整数行转换为字符,将字符串转换为日期

时间:2018-02-20 16:11:05

标签: r

我正在尝试将数据集中的整数转换为单个字符和日期,没有运气:我尝试了以下

# input data 
elog  <- read.csv("data.csv",sep = ",", as.is = T)
elog[1:3,]

elog$cust <- toString(elog$cust)
elog$date <- toString(elog$date)
elog$date <- as.Date(elog$date, "%Y%m%d");

它给了我以下内容:

转换前:

enter image description here

转换后:

enter image description here

我想重新创建的最终结果:

enter image description here

1 个答案:

答案 0 :(得分:0)

您需要as.character

# input data 
elog  <- read.csv("data.csv", sep = ",", as.is = T)
elog[1:3,]

elog$cust <- as.character(elog$cust)
elog$date <- as.character(elog$date)
elog$date <- as.Date(elog$date, "%Y%m%d")