Created
October 9, 2016 20:43
-
-
Save mschubert/3eeb5b35ed52ab21f138f0d799b15316 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
n = 1:1e7 | |
# use a loop | |
new_n = rep(NA, length(n)) | |
for (i in seq_along(n)) | |
new_n[i] = n[i] * 2 - 5 | |
# use *apply | |
new_n = sapply(n, function(x) x * 2 - 5) | |
# use vector operations | |
new_n = n * 2 - 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
point out here:
and