Skip to content

Instantly share code, notes, and snippets.

@docsteveharris
Last active October 21, 2016 10:16
Show Gist options
  • Save docsteveharris/541f3da241da6e8cb08ae4aee97ce713 to your computer and use it in GitHub Desktop.
Save docsteveharris/541f3da241da6e8cb08ae4aee97ce713 to your computer and use it in GitHub Desktop.
# Check all have same length
list.of.lists.2df <- function(l) {
'
Convert a list of lists to a data.frame
via http://stackoverflow.com/a/4227504/992999
'
# Check that all nested lists are of the same lenght
library(assertthat)
assert_that(sum(sapply(l, function(x) length(x)!=length(l[[1]])))==0)
d <- data.frame(t(sapply(l, c)))
return(d)
}
d <- list.of.lists.2df(l)
# Check all have same length
list.of.lists.2df <- function(l) {
'
Convert a list of lists to a data.frame
via http://stackoverflow.com/a/4227504/992999
'
# Check that all nested lists are of the same lenght
library(assertthat)
assert_that(sum(sapply(l, function(x) length(x)!=length(l[[1]])))==0)
d <- data.frame(t(sapply(l, c)))
return(d)
}
d <- list.of.lists.2df(l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment