I have a list that looks something like this, where the variables are of various lengths, and in a random order
> my.list <- lapply(list(c(2,1,3,4),c(2,3),c(4,2,3),c(1,3,4),c(1,4),c(2,4,1)),
function(x)letters[x])
> my.list
>my.list
[[1]]
[1] "b" "a" "c" "d"
[[2]]
[1] "b" "c"
[[3]]
[1] "d" "b" "c"
[[4]]
[1] "a" "c" "d"
[[5]]
[1] "a" "d"
[[6]]
[1] "b" "d" "a"
What I want to do is put this into a data frame, with NA where there are blanks. However, each row is in a random order, and I want each row in the data frame to be ordered such that it goes in alphabetical or numeric. Ideally the end result would look like the example below
>df
V1 V2 V3 V4
1 a b c d
2 NA b c NA
3 NA b c d
4 a NA c d
5 a NA NA d
6 a b NA d