I have a data.frame in R, like this:
fruits
X1 X2 X3
aa kiwi 15
ba orange 25
cc lemon 23
ba apple 17
cc lemon 19
cc orange 18
cc orange 21
ba banana 17
I'd like to replace all values in column X2 except "orange" and "lemon" with "other". How to do it in R?
Example data:
fruits <- structure(list(X1 = structure(c(1L, 2L, 3L, 2L, 3L, 3L, 3L, 2L
), .Label = c("aa", "ba", "cc"), class = "factor"), X2 = structure(c(3L,
5L, 4L, 1L, 4L, 5L, 5L, 2L), .Label = c("apple", "banana", "kiwi",
"lemon", "orange"), class = "factor"), X3 = c(15L, 25L, 23L,
17L, 19L, 18L, 21L, 17L)), .Names = c("X1", "X2", "X3"), class = "data.frame", row.names = c(NA,
-8L))