[R] check and verify

arun smartpink111 at yahoo.com
Tue Aug 28 14:49:22 CEST 2012


Hi,
Try this:
 test$A<-(test$A==test$C)*test$E
 test$B<-(test$B==test$D)*test$F
 test
#   A  B C D  E  F
#1  0  0 c d 40 30
#2 20  0 a b 20 10
#3  0 30 y m 50 30
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 within(test,{A<-(A==C)*E; B<-(B==D)*F})
 #  A  B C D  E  F
#1  0  0 c d 40 30
#2 20  0 a b 20 10
#3  0 30 y m 50 30
A.K.



----- Original Message -----
From: Sapana Lohani <lohani.sapana at ymail.com>
To: R help <r-help at r-project.org>
Cc: 
Sent: Tuesday, August 28, 2012 1:00 AM
Subject: [R] check and verify

Hi, 


I have 6 columns in my dataframe (test)

A B C D E F
a b c d 40 30
a f a b 20 10
x m y m 50 30

If character value in column A matches with that in column C, it gets the percentage in column E, similarly if value in column B matches the value in D, it gets the percentage in F column. If it doesn't match, it gets 0 percentage.


How can I do that ?

thanks

    [[alternative HTML version deleted]]

______________________________________________
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.





More information about the R-help mailing list