Skip to content
Prev 319102 / 398513 Next

data.frame with variable-length list

Note that
  c(list(1,2,3), list(4, 5,6), list(7,8,9, 10))
is identical to
  list(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

You want either
   list(list(1,2,3), list(4,5,6), list(7,8,9,10)) # list of 3 lists of numeric scalars
or
   list(c(1,2,3), c(4,5,6), c(7,8,9,10)) # list of 3 numeric vectors

In any case, you need to wrap it in I() when passing it to data.frame so it doesn't
get converted to columns of a data.frame.  E.g.,
+            type = c(1, 2, 3),
+            rtn = I( list(c(1,2,3), c(4,5,6), c(7,8,9,10)) ))
[[1]]
[1] 4 5 6
[1] 4 5 6
name type         rtn
1    a    1     1, 2, 3
2    b    2     4, 5, 6
3    c    3 7, 8, 9, 10

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com