This is following on from another question Extracting from Nested list to data frame
Using the updated answer I get my data frame I will start with.
I then use df <- data.frame(start = df3[5,])
So I'm left with:
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")
Now I'd like to get to the format:
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
I can use the following to find the columns that match
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"
So I think from here there must be a way I can get to my desired output.
Or I'm sure someone will show me a better way