[R] Want to convert list with vectore of dis similar lengths to data frame

JS Huang js.huang at protective.com
Thu Mar 5 15:04:35 CET 2015


Hi,
  
  The following works by appending NA to make up the maximum length of the
list.

> test4
$Row1
[1] "a" "b" "c" "d" "e"

$Row2
[1] "a" "b" "c" "d" "e" "f" "g"

$Row3
[1] "h" "i" "j" "k" "l" "m" "n"

> as.data.frame(t(sapply(1:length(test4),
> function(x){c(test4[[x]],rep(NA,max(sapply(1:length(test4),function(x)length(test4[[x]])))-length(test4[[x]])))})))
  V1 V2 V3 V4 V5   V6   V7
1  a  b  c  d  e <NA> <NA>
2  a  b  c  d  e    f    g
3  h  i  j  k  l    m    n



--
View this message in context: http://r.789695.n4.nabble.com/Want-to-convert-list-with-vectore-of-dis-similar-lengths-to-data-frame-tp4704196p4704200.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list