[R] Replace query

David Winsemius dwinsemius at comcast.net
Sun May 2 16:36:39 CEST 2010


On May 2, 2010, at 7:01 AM, burgundy wrote:

>
> Hi,
>
> I'm trying to replace all values equal to 1 in one file (a) with the  
> value
> in the corresponding column in a separate file (b). Example below.
> Any help (and brief notes if poss) much appreciated. Thanks!!
>
> file a:
> 0,0,1,1,0
> 1,0,0,0,1
> 0,0,0,0,0
> 1,0,1,1,0

You need to read the introductory material on reading files, and then  
you need to read the Posting Guide about how to present copy-pastable  
versions of r objects. Also look at:

?dput

>
> file b:
> 3,4,6,8,11

Once that is done:

t( t(a)*b)


>
> output request:
> 0,0,6,8,0
> 3,0,0,0,11
> 0,0,0,0,0
> 3,0,6,8,0
>
-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list