0

I have a huge data.I have tried to make an example but it is impossible because I have 10000 files and they are very huge. So i try to give what I need with the example below

Imagine I have a data like this 

d1 <- data.frame(y1=c(1,2,3,5,7),y2=c(4,5,6))
d2 <- data.frame(y1=c(3,2,1),y2=c(6,5,4))
d3 <- data.frame(y1=c(3,2,1,5),y2=c(6,5,4,NA))
my.list <- list(d1, d2,d3)

I want to have a data frame like this

1   4   3   6   3   6
2   5   2   5   2   5
3   6   1   4   1   4
5   NA          5   NA
7   NA              

I read this one What is the most efficient way to cast a list as a data frame? and as.data.frame flattens nested list into single row instead of creating row for each record and many other related post but I could not find a solution for it

I did

my.df <- do.call("cbind", lapply(my.list, data.frame))

error

Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 3, 4, 5

I do

do.call(cbind.data.frame, my.list)

error

Error in data.frame(..., check.names = FALSE) : 
  arguments imply differing number of rows: 3, 4, 5
Community
  • 1
  • 1
nik
  • 2,500
  • 5
  • 21
  • 48
  • What do you expect the output to look like after the cbind? It seems odd to try to cbind if you have a different number of rows. – MrFlick Dec 07 '16 at 21:19
  • 1
    With that data, a row bind might be better. `data.table::rbindlist(lapply(my.list, as.data.frame.list), fill = TRUE)` looks okay, except for the column types might need to be converted. – Rich Scriven Dec 07 '16 at 21:19
  • @Rich Scriven I made an example and output above, it is very difficult to post from my data because each file is huge – nik Dec 07 '16 at 21:56
  • @MrFlick I made an example and output above, it is very difficult to post from my data because each file is huge – nik Dec 07 '16 at 21:57
  • Why would you like to have a data.frame like that? Typically each row should represent one unit of observation and the columns should be attributes for that unit. What's the difference to you between "blank" values and "NA" values. Is this purely for display purposes? – MrFlick Dec 07 '16 at 22:16
  • @MrFlick because it is easier for me to also check them manually at least few of them and see if I am doing things right . NA is only for representation, it can be `blank` or even `NAN`or whatever constant – nik Dec 07 '16 at 22:19

0 Answers0