/explore

Click through on any links that interest you or select the planets on the right to continue exploring the Outer Web.
You are here

epiverse-trace.github.io
| | privefl.github.io

In this post, I talk about loops in R, why they can be slow and when it is okay to use them. Don't grow objects Let us generate a matrix of uniform values (max changing for every column). gen_grow <- function(n = 1e3, max = 1:500) { mat <- NULL for (m in max) { mat <- cbind(mat, runif(n, max = m)) } mat } set.seed(1) system.time(mat1 <- gen_grow(max = 1:500)) ## user system elapsed ## 0.333 0.189 0.523 system.time(mat2 <- gen_grow(max = 1:2000)) ## user system elapsed ## 6.183 7.603 13.803 gen_sapply <- function(n = 1e3, max = 1:500) { sapply(max, function(m) runif(n, max = m)) } set.seed(1) system.time(mat3 <- gen_sapply(max = 1:500)) ## user system elapsed ## 0.026 0.005 0.030 identical(mat3, mat1) ## [1] TRUE system.time(mat4 <- gen_sapply(max = 1:2000)) ...
4.9 parsecs

Travel
| |
| | zevross.com

The purrr package is a functional programming superstar which provides useful tools for iterating through lists and vectors, generalizing code and removing programming redundancies. The purrr tools...
6.7 parsecs

Travel
| |
| | aosmith.rbind.io

In this post I delve into the details of the R functions I've been using in my simulation examples, focusing on the replicate() function and the map family of functions from the purrr package. I spend a little time showing the parallels between the replicate() function and a for() loop.
5.8 parsecs

Travel
| |
| | www.huffpost.com

The trailer confirms the next season will premiere in April 2019.
17.3 parsecs

Travel
|