0

Consider this basic dataset:

myfruit <- tibble(fruit = c("apple", "orange", "apple", "pear", "banana"),
                  quantity = c("10","20","10","30", "40"))

Using R, how can I rename all values in the "fruit" column which display "apple" to "mango", without changing its associated "quantity" value? I know you can manually change the values but what is a more efficient method for larger datasets?

Any help would be much appreciated - many thanks, Karima

Rui Barradas
  • 57,195
  • 8
  • 29
  • 57
Karima
  • 259
  • 1
  • 9

1 Answers1

1

You can use the vectorized ifelse function here:

myfruit$fruit <- ifelse(myfruit$fruit == "apple",
                        "mango", myfruit$fruit)
Tim Biegeleisen
  • 451,927
  • 24
  • 239
  • 318