0

I have a data like this;

t1<-structure(list(`12/2018` = structure(list(Date = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("12/31/2018", 
"3/11/2011"), class = "factor"), X. = structure(c(1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "-", class = "factor"), 
    Value = c(0.2, 0, 0.1, 0.1, 0, 0, 0, 0, 0, 0, 0, 0, 0)), .Names = c("Date", 
"X.", "Value"), row.names = c(NA, 13L), class = "data.frame"), 
    `3/2011` = structure(list(Date = structure(c(2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("12/31/2018", 
    "3/11/2011"), class = "factor"), X. = structure(c(1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "-", class = "factor"), 
        Value = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)), .Names = c("Date", 
    "X.", "Value"), row.names = 14:26, class = "data.frame")), .Names = c("12/2018", 
"3/2011"))

And I want to create a dataframe by considering date column for both 2 objects in the list like below;

df<-data.frame("Day" = , "Month" = , "Year" = )

1 Answers1

1

To collapse the list into a dataframe, you could use rbind():

t2 <- rbind(t1$`12/2018`,t1$`3/2011`)

EDIT: In the comments, OP mentioned that they want to do this for arbitrary columns.

For this, use do.call(). You may also want to remove the row names:

t2 <- do.call(t1,rbind)
rownames(t2) <- c()

There are other questions on Stack Overflow which explain how to split columns, so I linked one in the comments.

SDS0
  • 500
  • 2
  • 8