[R] check and verify

PIKAL Petr petr.pikal at precheza.cz
Tue Aug 28 10:09:19 CEST 2012


Hi


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Sapana Lohani
> Sent: Tuesday, August 28, 2012 7:01 AM
> To: R help
> 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 ?

test<-read.table("clipboard", header=T)
test
  A B C D  E  F
1 a b c d 40 30
2 a f a b 20 10
3 x m y m 50 30

test[,3]%in%test[,1]*test[,5]
[1]  0 20  0
test[,4]%in%test[,2]*test[,6]
[1]  0 10 30

Is this what you want?

Regards
Petr


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