Last active
October 21, 2016 10:16
-
-
Save docsteveharris/541f3da241da6e8cb08ae4aee97ce713 to your computer and use it in GitHub Desktop.
This file contains 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
# 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) |
This file contains 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
# 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