【发布时间】:2017-01-05 15:16:16
【问题描述】:
这是从另一个问题开始的 Extracting from Nested list to data frame
使用更新后的答案,我得到了我将开始使用的数据框。
然后我使用df <- data.frame(start = df3[5,])
所以我只剩下:
dput(df)
structure(list(start.X1_1 = structure(4L, .Names = "experience.start", .Label = c("",
" ", "1", "2015"), class = "factor"), start.X2_2 = structure(3L, .Names = "experience.start", .Label = c(" ",
"1", "2011"), class = "factor"), start.X3_2 = structure(3L, .Names = "experience.start", .Label = c(" ",
"1", "2007"), class = "factor"), start.X4_2 = structure(NA_integer_, .Names = "experience.start", .Label = c(" ",
"1"), class = "factor"), start.X5_2 = structure(NA_integer_, .Names = "experience.start", .Label = c(" ",
"1"), class = "factor"), start.X6_2 = structure(NA_integer_, .Names = "experience.start", .Label = c(" ",
"1"), class = "factor"), start.X7_2 = structure(NA_integer_, .Names = "experience.start", .Label = c(" ",
"1"), class = "factor"), start.X8_2 = structure(NA_integer_, .Names = "experience.start", .Label = c(" ",
"1"), class = "factor"), start.X9_2 = structure(NA_integer_, .Names = "experience.start", .Label = c(" ",
"1"), class = "factor"), start.X10_3 = structure(3L, .Names = "experience.start", .Label = c(" ",
"1", "2016", "3000"), class = "factor"), start.X11_3 = structure(3L, .Names = "experience.start", .Label = c(" ",
"1", "2015", "3000"), class = "factor"), start.X12_3 = structure(4L, .Names = "experience.start", .Label = c("",
" ", "1", "2015", "2016", "EE"), class = "factor"), start.X13_3 = structure(4L, .Names = "experience.start", .Label = c("",
" ", "1", "2014", "2015"), class = "factor"), start.X14_3 = structure(3L, .Names = "experience.start", .Label = c(" ",
"1", "2013", "2014"), class = "factor"), start.X15_3 = structure(3L, .Names = "experience.start", .Label = c(" ",
"1", "2010", "2011", "Virtusa"), class = "factor")), .Names = c("start.X1_1",
"start.X2_2", "start.X3_2", "start.X4_2", "start.X5_2", "start.X6_2",
"start.X7_2", "start.X8_2", "start.X9_2", "start.X10_3", "start.X11_3",
"start.X12_3", "start.X13_3", "start.X14_3", "start.X15_3"), row.names = "experience.start", class = "data.frame")
现在我想了解格式:
v1 v2 v3 v4 v5 v6 v7 v8
1 2015
2 2011 2007 null null null null null null
3 2016 2015 2015 2015 2013 2010
我可以使用以下内容来查找匹配的列
sR <- function(x, n){
substr(x, nchar(x)-n+1, nchar(x))}
sR(names(df),2)
[1] "_1" "_2" "_2" "_2" "_2" "_2" "_2" "_2" "_2" "_3" "_3" "_3" "_3" "_3" "_3"
所以我认为从这里必须有一种方法可以达到我想要的输出。
或者我相信有人会告诉我更好的方法
【问题讨论】: