[R] Use or ??
arun
smartpink111 at yahoo.com
Wed Aug 29 06:54:25 CEST 2012
HI,
If I understand your question correctly, this should give the result:
dat1<-read.table(text="
A B C
a b a
x y z
",sep="",header=TRUE,stringsAsFactors=FALSE)
within(dat1,{new_column<-ifelse(A==C|B==C,"y","n")})
# A B C new_column
#1 a b a y
#2 x y z n
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 8:06 PM
Subject: [R] Use or ??
Hi, My data frame looks like
A B C
a b a
x y z
I want to add a new column which says "y" if either A or B matches with C and "n" if there is no match. 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