我有一个数据框,每列包含以下变量类别:
"date" "numeric" "numeric" "list" "list" "numeric"
每行中的数据如下所示:
1978-01-01, 12.5, 6.3, c(0,0,0.25,0.45,0.3), c(0,0,0,0.1,0.9), 72
我想将其转换为每列一个值的矩阵或数据框,因此结果应如下所示:
1978-01-01, 12.5, 6.3, 0, 0, 0.25, 0.45, 0.3, 0, 0, 0, 0.1, 0.9, 72
我试过使用:
j<-unlist(input)
output<-matrix(j,nrow=nrow(input),ncol=length(j)/nrow(input))
但它弄乱了输出中行的顺序。
任何想法?
附加信息:
上面的例子稍微简化了,dput(head(input))
返回下面的例子:
structure(list(DATE = structure(c(2924, 2925, 2926, 2927, 2928,
2929), class = "Date"), TEMP_MEAN_M0 = c(-7.625, -7.375, -6,
-5.5, -7.625, -9.625), SLP_MEAN_M0 = c(1012.125, 991.975, 989.825,
986.675, 988.95, 993.075), WIND_DIR_RF_M0 = structure(list(`2.counts` = c(0,
0.625, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.125, 0, 0, 0, 0.125), `3.counts` = c(0.75,
0.25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), `4.counts` = c(0.375,
0.125, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.125, 0.125, 0, 0, 0), `5.counts` = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.125,
0, 0, 0.125, 0.375, 0.25, 0, 0, 0, 0, 0, 0, 0, 0, 0), `6.counts` = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.125,
0, 0.25, 0.125, 0.25, 0.25, 0, 0, 0, 0, 0, 0, 0, 0, 0), `7.counts` = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0.125, 0.5, 0.375, 0, 0, 0, 0, 0, 0, 0, 0, 0)), .Names = c("2.counts",
"3.counts", "4.counts", "5.counts", "6.counts", "7.counts")),
CEIL_HGT_RF_M0 = structure(list(`2.counts` = c(0.625, 0,
0, 0, 0, 0, 0, 0, 0, 0.375), `3.counts` = c(0.75, 0.125,
0, 0.125, 0, 0, 0, 0, 0, 0), `4.counts` = c(0.25, 0.125,
0, 0.125, 0, 0, 0, 0, 0.25, 0.25), `5.counts` = c(0, 0, 0,
0, 0, 0, 0, 0, 0.125, 0.875), `6.counts` = c(0, 0, 0, 0,
0, 0, 0, 0, 0, 1), `7.counts` = c(0, 0, 0, 0, 0, 0, 0, 0,
0, 1)), .Names = c("2.counts", "3.counts", "4.counts", "5.counts",
"6.counts", "7.counts")), WIND_SPD_MEAN_M0 = c(12.8125, 18.7375,
6.175, 8.175, 10.5375, 16.5375)), .Names = c("DATE", "TEMP_MEAN_M0",
"SLP_MEAN_M0", "WIND_DIR_RF_M0", "CEIL_HGT_RF_M0", "WIND_SPD_MEAN_M0"
), row.names = c(NA, 6L), class = "data.frame")