Lets change the some of pesticide names in the spray
column of the InsectSprays
data frame to be more informative than just "A", "B", "C", etc.
First, coerce the spray
variable from a factor vector into a character vector, for reasons…
InsectSprays$spray <- as.character(InsectSprays$spray)
Then, subset the combination of rows and columns you wish to overwrite, and assign a replacement value to them.
InsectSprays[InsectSprays$spray=='A','spray'] <- "SPRAY_OF_DOOOOM"
InsectSprays[InsectSprays$spray=='B','spray'] <- "fairy_dust"
InsectSprays[c(1,21),]
## count spray
## 1 10 SPRAY_OF_DOOOOM
## 21 19 fairy_dust