Skip to content
Prev 323518 / 398503 Next

Dataframe and conditions

#this should also work

?within(X,a<- ifelse(b,c,a))
#? a???? b c
#1 2? TRUE 2
#2 2? TRUE 2
#3 1 FALSE 2
#4 1 FALSE 2
#5 1 FALSE 2
#6 2? TRUE 2
A.K.

----- Original Message -----
From: Pascal Oettli <kridox at ymail.com>
To: fgrelier <fgrelier at weborama.com>
Cc: r-help at r-project.org
Sent: Tuesday, May 14, 2013 4:47 AM
Subject: Re: [R] Dataframe and conditions

Hello,

One approach is using "ifelse":
b=c(TRUE,TRUE,FALSE,FALSE,FALSE,TRUE), c=c(2,2,2,2,2,2))
?  a? ?  b c
1 1? TRUE 2
2 1? TRUE 2
3 1 FALSE 2
4 1 FALSE 2
5 1 FALSE 2
6 1? TRUE 2
?  a? ?  b c
1 2? TRUE 2
2 2? TRUE 2
3 1 FALSE 2
4 1 FALSE 2
5 1 FALSE 2
6 2? TRUE 2

Hope this helps,
Pascal
On 05/14/2013 05:06 PM, fgrelier wrote:
______________________________________________
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.