Created
December 12, 2019 18:04
-
-
Save benlistyg/7af3cfe82adb9f28ac50e32280515ad7 to your computer and use it in GitHub Desktop.
Programmatically recode variables (for @lpsatchell)
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
# Generate Fake Data | |
fake_data <- sample(x = c(1:5), size = 100, replace = T) %>% | |
matrix(ncol = 10) | |
# We want to programmatically recode these. | |
# 5 to 1 (and vice versa) | |
# 4 to 2 (and vice versa) | |
recoding_function <- function(x){ | |
(max(x) - x) + 1 | |
} | |
recoded_fake_data <- apply(fake_data, 2, recoding_function) | |
fake_data | |
recoded_fake_data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment