Skip to content
Prev 138274 / 398506 Next

Replace a list of values in data frame

On Friday 29 February 2008 (14:50:53), Silvia Lipski wrote:
What about:

colorful <- within(colorful,
		test1 <- replace(response,
			c("black","brown"),
			"dark"
			)
		)

or

colorful <- within(colorful,
		test1 <- response
		test1[test1 %in% c("black","brown")] <- "dark"
		)