Skip to content
Prev 310431 / 398506 Next

as.data.frame(do.call(rbind,lapply)) produces something weird

The following code:
--8<---------------cut here---------------start------------->8---
a b.x b.y c.x c.y
1 a1   1   1   1   1
2 a2   2   4   8  64
3 a3   3   9  27 729
--8<---------------cut here---------------end--------------->8---
the appearance of z is good, but str() and summary betray some weirdness:
--8<---------------cut here---------------start------------->8---
'data.frame':	3 obs. of  5 variables:
 $ a  :List of 3
  ..$ : chr "a1"
  ..$ : chr "a2"
  ..$ : chr "a3"
 $ b.x:List of 3
  ..$ : int 1
  ..$ : int 2
  ..$ : int 3
 $ b.y:List of 3
  ..$ : int 1
  ..$ : int 4
  ..$ : int 9
 $ c.x:List of 3
  ..$ : int 1
  ..$ : int 8
  ..$ : int 27
 $ c.y:List of 3
  ..$ : int 1
  ..$ : int 64
  ..$ : int 729
--8<---------------cut here---------------end--------------->8---
how do I ensure that the columns of z are vectors, as in
--8<---------------cut here---------------start------------->8---
a b.x b.y c.x c.y
1 a1   1   1   1   1
2 a2   2   4   8  64
3 a3   3   9  27 729
'data.frame':	3 obs. of  5 variables:
 $ a  : Factor w/ 3 levels "a1","a2","a3": 1 2 3
 $ b.x: num  1 2 3
 $ b.y: num  1 4 9
 $ c.x: num  1 8 27
 $ c.y: num  1 64 729
--8<---------------cut here---------------end--------------->8---
thanks!