change one value in dplyr in r

To change one value in dplyr in R, you first need to use the filter() function to select the row(s) that contain the value you want to change. Then, you can use the mutate() function to change the value. Here's an example:

main.r
library(dplyr)

# create a sample data frame
df <- data.frame(names = c("Alice", "Bob", "Charlie"),
                 age = c(25, 30, 35))

# select the row with "Bob"
df <- df %>% 
  filter(names == "Bob")

# change Bob's age to 32
df <- df %>% 
  mutate(age = 32)

# combine with the original data frame
df <- bind_rows(df, df %>% filter(names != "Bob"))

# view the updated data frame
df
390 chars
20 lines

In this example, we first select the row with "Bob" using filter(). We then use mutate() to change Bob's age to 32. Finally, we combine this modified data frame with the original data frame using bind_rows(), and view the updated data frame.

gistlibby LogSnag