I am using replace function to replace numbers with characters in a list but seem to need to add an extra value to the index list for the code to work. (See example)
Simple version of by problem is that I have a list (0,1) and I want to replace 0 with "a" and 1 with "b".
replace(0:1, 0:1, c("a","b"))
Generates following results
[1] "a" "1"
Warning message:
In x[list] <- values :
number of items to replace is not a multiple of replacement length
when extend index list to 0:2 I get the desired output
> replace(0:1, 0:2, c("a","b"))
[1] "a" "b"
I obviously don't understand how the replace function works but I can't seem to figure out what I am missing.