Skip to content

collapsing datasets from a list #6

@andkov

Description

@andkov

@casslbrown

This is a reproducible example for combining a list of datasets into a single data frame.

year1 <- data.frame(
  id   = c(1,2),
  var1 = c(11,12),
  var2 = c(22,23 )
)

year2 <- data.frame(
  id = c(1,2),
  var1 = c(33,34),
  var2 = c(44,45),
  var3 = c(55,56)
  
)

dto <- list(
  `1` = year1, 
  `2` = year2)

ds <- plyr::ldply(dto,data.frame, .id = "year")
> ds %>% dplyr::arrange(id)
  year id var1 var2 var3
1    1  1   11   22   NA
2    2  1   33   44   55
3    1  2   12   23   NA
4    2  2   34   45   56

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions