How to Apply the replace() Function in R (Example Code)
On this page you’ll learn how to exchange values in a vector using the replace function in R.
Creating Exemplifying Data
my_vec <- letters[1:5] # Creating vector my_vec # Returning example vector # "a" "b" "c" "d" "e" |
my_vec <- letters[1:5] # Creating vector my_vec # Returning example vector # "a" "b" "c" "d" "e"
Example: Using replace() Function to Replace Certain Values in Vector
replace(my_vec, c(1, 3), "XXX") # Using replace function # "XXX" "b" "XXX" "d" "e" |
replace(my_vec, c(1, 3), "XXX") # Using replace function # "XXX" "b" "XXX" "d" "e"