Skip to content
Prev 206434 / 398503 Next

transposing a list of vectors

Thanks, Henrique
I *do* need to preserve the type of each list element (num or chr).
Thus, a first step might be

 > as.data.frame(testlist, stringsAsFactors=FALSE)
  shape cell.fill back.fill scale.max
1     0       red     white       100
2     0      blue     white       100
3     2     green     white       100
 > str(as.data.frame(testlist, stringsAsFactors=FALSE))
'data.frame':   3 obs. of  4 variables:
 $ shape    : num  0 0 2
 $ cell.fill: chr  "red" "blue" "green"
 $ back.fill: chr  "white" "white" "white"
 $ scale.max: num  100 100 100

I think, with this mod, your #2 gives me what I want:

 wanted.henrique <- lapply(split(x <- as.data.frame(testlist, 
stringsAsFactors=FALSE), 1:nrow(x)), as.list)
 > str(wanted.henrique)
List of 3
 $ 1:List of 4
  ..$ shape    : num 0
  ..$ cell.fill: chr "red"
  ..$ back.fill: chr "white"
  ..$ scale.max: num 100
 $ 2:List of 4
  ..$ shape    : num 0
  ..$ cell.fill: chr "blue"
  ..$ back.fill: chr "white"
  ..$ scale.max: num 100
 $ 3:List of 4
  ..$ shape    : num 2
  ..$ cell.fill: chr "green"
  ..$ back.fill: chr "white"
  ..$ scale.max: num 100
Henrique Dallazuanna wrote: