Re: [R] Replace a list of values in data frame

From: Martin Elff <elff_at_sowi.uni-mannheim.de>
Date: Mon, 03 Mar 2008 14:27:22 +0100

On Friday 29 February 2008 (14:50:53), Silvia Lipski wrote:
> Dear R-users,
>
> I am sorry if I ask for something that has been asked
> before, however, I still could not solve my little
> problem by consulting the previous thread on this
> topic:
>
> I would like to replace several values in a data
> frame, such as in:
>
> colorful
>   subject response
> 1      me    black  
> 2      me    brown  
> 3     you      red  
> 4      me    black  
> 5     you    brown  
>
> read in with read.table()
>
> I would like to replace both "black" and "brown" by
> "dark".

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"
		)

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 03 Mar 2008 - 13:34:01 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 03 Mar 2008 - 14:30:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive