Created
September 22, 2016 01:37
-
-
Save certifiedwaif/a16c4acf4b4a74635f6dcc961fc85429 to your computer and use it in GitHub Desktop.
What's a better way to loop over all combinations of vp, vn and vR2, producing p*n, p and R2 and ending up with an n by 3 data frame or matrix?
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
library(purrr) | |
vp <- c(10, 20, 50, 100, 500, 1000) | |
vn <- c(1.1, 1.25, 1.5, 2, 5, 10) | |
vR2 <- seq(from=0.00, to=1.00, by = 1e-2) | |
df <- map(vp, function(p) { | |
map(vn, function(n) { | |
map(vR2, function(R2) {c(p*n, p, R2)}) | |
}) | |
}) %>% as.data.frame %>% t | |
rownames(df) <- NULL | |
colnames(df) <- c("vn", "vp", "vR2") | |
df <- as.data.frame(df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment