0

I have a list that has a length 0f 173, each element of which has 48 items. I want to make a dataframe out of this that ends up with 48 rows and 173 columns. The names of the items dont matter and dont match so how do I do this?

dput(tra[[1]][1:5,1:5])
structure(list(c..0.0....93.. = structure(c(1L, NA, NA, NA, NA
), .Label = c("0|0", "93"), class = "factor"), c..0.0....127.. = structure(c(1L, 
NA, NA, NA, NA), .Label = c("0|0", "127"), class = "factor"), 
    c..0.0....127...1 = structure(c(1L, NA, NA, NA, NA), .Label = c("0|0", 
    "127"), class = "factor"), c..0.0....127...2 = structure(c(1L, 
    NA, NA, NA, NA), .Label = c("0|0", "127"), class = "factor"), 
    c..0.0....127...3 = structure(c(1L, NA, NA, NA, NA), .Label = c("0|0", 
    "127"), class = "factor")), .Names = c("c..0.0....93..", 
"c..0.0....127..", "c..0.0....127...1", "c..0.0....127...2", 
"c..0.0....127...3"), row.names = c("1", "NA", "NA.1", "NA.2", 
"NA.3"), class = "data.frame")

I tried:

> ft <- data.frame(matrix(unlist(tra), nrow=173, byrow=T))
Error in matrix(unlist(tra), nrow = 173, byrow = T) : 
'data' must be of a vector type, was 'NULL'
AND 
> traa <- do.call(rbind.data.frame, tra)
Error in match.names(clabs, names(xi)) : 
names do not match previous names
Simon O'Hanlon
  • 58,647
  • 14
  • 142
  • 184
cianius
  • 2,272
  • 6
  • 28
  • 41
  • From your description I think you want `do.call(data.frame, tra)`. However, that doesn't match up with your attempt to provide data. The first element of `tra` seems to be a data.frame? – Roland Oct 28 '13 at 20:02
  • No that creates a dataframe with one row and 8304 columns... Yes tra has 173 data frames each of which has one row and 48 columns. – cianius Oct 29 '13 at 01:43
  • 1
    So maybe `do.call(data.frame, lapply(tra, unlist))`? Hard to say without [a good minimal reproducible example](http://stackoverflow.com/a/5963610/1412059). – Roland Oct 29 '13 at 07:57

0 Answers0