Created
January 14, 2020 02:22
-
-
Save selva86/a74918e808a8cd79c5f847fa03d254e0 to your computer and use it in GitHub Desktop.
Practice exercise for master R course
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
# 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