[R] replace values

David Winsemius dwinsemius at comcast.net
Sat Dec 3 15:33:17 CET 2011


On Dec 3, 2011, at 8:41 AM, syrvn wrote:

> Hello,
>
>
> imagine the following data.frame:
>
> ID name
> 1 *_A
> 2 *_A
> 3 *_B
> 4 *_B
>
> * = can be any pattern
>
> I want to replace every row which ends with _A by 1 and every row  
> which ends
> by _B with a 0

You can use grep(patt, x, value=TRUE) to return vlaues that can be  
used in the prior answers to your earlier question today.

I would have worked it out and tested the strategy, but you continue  
to fail to produce workable examples.... and then apologize that  
people are "confused" by them. We are NOT confused... only annoyed ...  
that you fail to use dput() or code for constructing workable code.

-- 
David.
>
> so that the data.frame looks like the following:
>
> ID name
> 1 1
> 2 1
> 3 0
> 4 0
>
>
> Which function do I use best to achieve this?
>
> Cheers,
> Syrvn
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/replace-values-tp4153301p4153301.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list