[R] question for if else

2006-12-08 Thread Aimin Yan
I have a data set like this I want to assign outward to Y if sc 90 and assign inward to Y if sc=90. then cbind(p1982,Y) to get like these p aa as ms cur sc Y 1 154l_aa ARG 152.04 108.83 -0.1020140 92.10410 inward 2 154l_aa THR 15.86 28.32 0.2563560 103.67100inward 3 154l_aa ASP 65.13

Re: [R] question for if else

2006-12-08 Thread jim holtman
If p1982 is a data.frame: p1982$Y - ifelse(p1982$sc90, 'inward', 'outward') If it is a matrix p1982 - cbind(p1982, Y=ifelse(p1982[,'sc']90, 'inward', 'outward')) On 12/8/06, Aimin Yan [EMAIL PROTECTED] wrote: I have a data set like this I want to assign outward to Y if sc 90 and assign

Re: [R] question for if else

2006-12-08 Thread jim holtman
Hopefully it is a dataframe or else you matrix will be converted to character; forgot that when I sent it. On 12/8/06, jim holtman [EMAIL PROTECTED] wrote: If p1982 is a data.frame: p1982$Y - ifelse(p1982$sc90, 'inward', 'outward') If it is a matrix p1982 - cbind(p1982,

[R] question for IF ELSE usage

2005-07-12 Thread ecoinfo
Hi R users, Maybe the question is too simple. In a IF ... ELSE ... statement if(cond) cons.expr else alt.expr, IF and ELSE should be at the same line? For example, if (x1==12) { y1 - 5 }else { y1 - 3 } is right, while if (x1==12) { y1 - 5 } else # Error: syntax error { y1 - 3 } is wrong?

Re: [R] question for IF ELSE usage

2005-07-12 Thread Marc Schwartz (via MN)
On Tue, 2005-07-12 at 16:22 +0200, ecoinfo wrote: Hi R users, Maybe the question is too simple. In a IF ... ELSE ... statement if(cond) cons.expr else alt.expr, IF and ELSE should be at the same line? For example, if (x1==12) { y1 - 5 }else { y1 - 3 } is right, while if

Re: [R] question for IF ELSE usage

2005-07-12 Thread ecoinfo
Marc, I see. Thanks. Xiaohua On 7/12/05, Marc Schwartz (via MN) [EMAIL PROTECTED] wrote: On Tue, 2005-07-12 at 16:22 +0200, ecoinfo wrote: Hi R users, Maybe the question is too simple. In a IF ... ELSE ... statement if(cond) cons.expr else alt.expr, IF and ELSE should be at the

[R] question about if else

2004-02-27 Thread Svetlana Eden
Today is a good day for asking question, I guess. c() NULL length(c())==0 [1] TRUE r = ifelse(length(c())!=0, c(), c(1,2)) ### OK r = c() ### OK r = ifelse(length(c())==0, c(), c(1,2)) ### why this is not OK (given the previous two)? Error in

RE: [R] question about if else

2004-02-27 Thread Liaw, Andy
You need to (re-)read ?ifelse. In ifelse(L, v1, v2), L is suppose to be a vector of logicals (or an expression that evaluates to one), and v1 and v2 are vectors of same length as L; i.e., ifelse() vectorizes if ... else In the first case: r = ifelse(length(c())!=0, c(), c(1,2))

Re: [R] question about if else

2004-02-27 Thread Don MacQueen
ifelse() has three arguments, named 'test', 'yes', and 'no'. In both of your two examples, you gave it a test argument of length equal to 1. That is, both length(c())!=0 and length(c())==0 are expressions which when evaluated have length equal to 1. Therefore, the ifelse() function wants to