我有一个13x2的日期列表。我需要将其转换为26x1列表,第二列移动到第一列以下,因此我可以按日期对其进行排序。如何才能做到这一点?它必须简单,但无法弄明白。非常感谢。
#13x2 list of dates:
nfpdates1 <- list(structure(c(10963, 10991, 11019, 11054, 11082, 11110, 11145,11173, 11201, 11236, 11264, 11299, 10961), class = "Date"), structure(c(13518,13546, 13581, 13609, 13637, 13665, 13700, 13728, 13763, 13791,13819, 13854, 13517), class = "Date"))
#This is what nfpdates1 looks like:
[[1]]
[1] "2000-01-07" "2000-02-04" "2000-03-03" "2000-04-07" "2000-05-05"
[6] "2000-06-02" "2000-07-07" "2000-08-04" "2000-09-01" "2000-10-06"
[11] "2000-11-03" "2000-12-08" "2000-01-05"
[[2]]
[1] "2007-01-05" "2007-02-02" "2007-03-09" "2007-04-06" "2007-05-04"
[6] "2007-06-01" "2007-07-06" "2007-08-03" "2007-09-07" "2007-10-05"
[11] "2007-11-02" "2007-12-07" "2007-01-04"
答案 0 :(得分:1)
您可以使用rbindlist
中的data.table
,
library(data.table)
rbindlist(lapply(nfpdates1, as.data.frame))
#X[[i]]
#1: 2000-01-07
#2: 2000-02-04
#3: 2000-03-03
#4: 2000-04-07
#5: 2000-05-05
#6: 2000-06-02
答案 1 :(得分:0)
基础R实施:
outputDates <- do.call('cbind',nfpdates1)
class(outputDates) <- "Date"
outputDate
[1] "2000-01-07" "2000-02-04" "2000-03-03" "2000-04-07" "2000-05-05"
[6] "2000-06-02" "2000-07-07" "2000-08-04" "2000-09-01" "2000-10-06"
[11] "2000-11-03" "2000-12-08" "2000-01-05" "2007-01-05" "2007-02-02"
[16] "2007-03-09" "2007-04-06" "2007-05-04" "2007-06-01" "2007-07-06"
[21] "2007-08-03" "2007-09-07" "2007-10-05" "2007-11-02" "2007-12-07"
[26] "2007-01-04"
应该这样做。