You could do
sales_data$status[
sales_data$month == 'Jan' & sales_data$dept_name == 'Production'] <- "Good result"
Using replace
sales_data$status <- with(sales_data,
replace(status, month == 'Jan' & dept_name == 'Production', "Good result"))
We can also integrate this in dplyr
chain.
library(dplyr)
sales_data %>%
mutate(status = replace(status, month == 'Jan' & dept_name == 'Production',
"Good result"))
or with case_when
sales_data %>%
mutate(status = case_when(month == 'Jan' & dept_name =='Production'~"Good result",
TRUE ~ status))
subset
filter the dataframe based on conditions provided and does not update them.