My question is I have three columns of integers representing dates. If I use
as.Date(x,origin="1970-01-01")
for each individual column, it works. However, if I use sapply
as
sapply(data,function(x)as.Date(x,origin="1970-01-01"))
it does not work. Any ideas about how to solve the problem efficiently? The reproducible codes are as below
data=data.frame(time1=c(10189,11655,10914,12013,10934),time2=c(11758,10696,9784,10725,11225))
sapply(data,function(x)as.Date(x,origin="1970-01-01"))
The result does not change at all. but use
as.Date(data$time1,origin="1970-01-01")
it can work.