Skip to content

Instantly share code, notes, and snippets.

@mmparker
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save mmparker/22543b577fbcc5432f0a to your computer and use it in GitHub Desktop.

Select an option

Save mmparker/22543b577fbcc5432f0a to your computer and use it in GitHub Desktop.
# Dummy list
z <- list(list('a' = 1, 'b' = 2, 'c' = 3), list('a' = 4, 'b' = 5, 'c' = 6))
# If you just want to stack all of the values, not keeping any of the list name data
# but ensuring they're all of one type
data.frame(values = as.numeric(unlist(z)))
# ldply() automatically keeps the list element names as a ".id" column
z_named <- list('group1' = list('a' = 1, 'b' = 2, 'c' = 3), 'group2' = list('a' = 4, 'b' = 5, 'c' = 6))
# Iterate over the list of *names*
ldply(z_named, .fun = function(x) {
# Convert to a data.frame that preserves the list name
data.frame(value = as.numeric(unlist(x)))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment