您似乎想将列表转换为数据框。请尝试以下操作:
### creating a list similar to your example
mylist <- list("x1", c("x2", "x6"), c("x1", "x3"), "x2", c("x2", "x6", "x7"))
### determining the length of the longest string in the list
maxlength <- max(sapply(mylist, length))
### creating a function to set the lengths of all elments in the list to maxlength
myfct <- function(x){
if(length(x) == maxlength){return(x)}
if(length(x) != maxlength){return(c(x, rep(NA, maxlength-length(x))))}
}
### here the final output
> t(sapply(mylist, FUN = myfct))
[,1] [,2] [,3]
[1,] "x1" NA NA
[2,] "x2" "x6" NA
[3,] "x1" "x3" NA
[4,] "x2" NA NA
[5,] "x2" "x6" "x7"