Skip to content
Course Notes: Writing Efficient R Code
Course Notes
Use this workspace to take notes, store code snippets, and build your own interactive cheatsheet!
Note that the data from the course is not yet added to this workspace. You will need to navigate to the course overview page, download any data you wish to use, and add it to the file browser.
# Import any packages you want to use here
Take Notes
Add notes here about the concepts you've learned and code cells with code you want to keep.
Add your notes here
# Add your code snippets here
n <- 30000
# Fast code
pre_allocate <- function(n) {
x <- numeric(n) # Pre-allocate
for(i in 1:n)
x[i] <- rnorm(1)
x
}
#hardware Check
library(benchmarkme)
get_ram()
get_cpu()
#timecheck
system.time(sqrt(1:1e7))
#calculating rows
function(x){rowSums(x)}
#matrix faster than data frame
matrix(sample(1:6, 6, replace = TRUE), ncol = 2)