Last active
August 29, 2015 14:06
-
-
Save mmparker/22543b577fbcc5432f0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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