Skip to content

Instantly share code, notes, and snippets.

@selva86
Created January 14, 2020 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selva86/a74918e808a8cd79c5f847fa03d254e0 to your computer and use it in GitHub Desktop.
Save selva86/a74918e808a8cd79c5f847fa03d254e0 to your computer and use it in GitHub Desktop.
Practice exercise for master R course
# 1. Direct assignment
system.time ({
item_id_hypo <- numeric()
for(i in 1:10000000){
item_id_hypo[i] <- i
}
item_id_hypo
})
# 2. Preallocate memory
system.time ({
item_id_hypo <- numeric(10000000)
for(i in 1:10000000){
item_id_hypo[i] <- i
}
item_id_hypo
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment