Re: [R] if statements on vectors

2011-02-24 Thread kamel gaanoun
Or simply do : position <- as.numeric(trend1 == trend2 ) position 2011/2/24 Dimitris Rizopoulos > there are also vectorized logical operators; have a look at the help page > ?'&', and try this: > > > trend1 <- c(1,1,1,1,1,1,-1,-1,-1,-1,-1,-1) > trend2 <- c(1,1,1,1,1,1,1,1,1,1,1,-1) > > position

Re: [R] if statements on vectors

2011-02-24 Thread Kushan Thakkar
Thanks all. This works.. On Thu, Feb 24, 2011 at 3:43 AM, Jim Lemon wrote: > On 02/24/2011 08:37 PM, Dimitris Rizopoulos wrote: > >> there are also vectorized logical operators; have a look at the help >> page ?'&', and try this: >> >> trend1 <- c(1,1,1,1,1,1,-1,-1,-1,-1,-1,-1) >> trend2 <- c(1,

Re: [R] if statements on vectors

2011-02-24 Thread Jim Lemon
On 02/24/2011 08:43 PM, Jim Lemon wrote: Oops, forgot about the zero! trunc((trend1 * trend2 + 1)/2) Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posti

Re: [R] if statements on vectors

2011-02-24 Thread Jim Lemon
On 02/24/2011 08:37 PM, Dimitris Rizopoulos wrote: there are also vectorized logical operators; have a look at the help page ?'&', and try this: trend1 <- c(1,1,1,1,1,1,-1,-1,-1,-1,-1,-1) trend2 <- c(1,1,1,1,1,1,1,1,1,1,1,-1) position <- as.numeric((trend1 == 1 & trend2 == 1) | (trend1 == -1 &

Re: [R] if statements on vectors

2011-02-24 Thread Ivan Calandra
Hi, I think you want ifelse(). Assuming that length(trend2)=12 and not 14 as in the data you provided, that should work: position <- ifelse((trend1==1 & trend2==1)|(trend1==-1 & trend2==-1),1,0) #btw, note the single "&" and single "|", not double HTH, Ivan Le 2/24/2011 09:41, Kushan Thak

Re: [R] if statements on vectors

2011-02-24 Thread Dimitris Rizopoulos
there are also vectorized logical operators; have a look at the help page ?'&', and try this: trend1 <- c(1,1,1,1,1,1,-1,-1,-1,-1,-1,-1) trend2 <- c(1,1,1,1,1,1,1,1,1,1,1,-1) position <- as.numeric((trend1 == 1 & trend2 == 1) | (trend1 == -1 & trend2 == -1)) position I hope it helps. Best,

[R] if statements on vectors

2011-02-24 Thread Kushan Thakkar
I have two vectors: both have possible values of 1,-1, or 0 trend1 <- c(1,1,1,1,1,1,-1,-1,-1,-1,-1,-1) trend2 <- c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,) i want to create a third vector that is conditional upon these two vectors: if (trend2 == 1 && trend1 == 1) {position <- 1} elseif (trend2 == -1 && tre

Re: [R] If statements for multiple arrays

2010-09-16 Thread David Winsemius
I see Joshua has kindly offered some resources to turn you from your path of erroR and sins against the interpreteR, but if you want to do extra penance, you might consider reading the R-FAQ (although your issue if if and "&&" is surprisingly not included there) : http://cran.r-project.org/

Re: [R] If statements for multiple arrays

2010-09-16 Thread Phil Spector
George - I think you're looking for the ifelse function: X = c(100,125,110,90) Y = c(200,110,150,200) Z = c(125,105,130,75) AA = c(150,140,200,65) result = ifelse(X < Z & Y > Z,AA - Z,NA) result [1] 25 NA 70 NA result[!is.na(result)] [1] 25 70 (I'm assuming you said 50 when you meant 70.)

Re: [R] If statements for multiple arrays

2010-09-16 Thread Joshua Wiley
Hello George, Two things should help you move from one case to multiple. First, if is designed for a single result (TRUE or FALSE), but you actually want many, so you can use the ifelse() function. Second, since you want to examine each element, you just want '&', not '&&'. I believe this does

[R] If statements for multiple arrays

2010-09-16 Thread George Coyle
Hello, I wrote this code which works fine on a single observation: x<-100 y<-200 z<-125 aa<-150 if(xz) {aa-z} result: 25 I am trying to apply this logic where x,y,z,and aa are arrays but with very little success. I have tried using loops and whiles but I always get errors of various types. I h

Re: [R] IF STATEMENTS

2009-07-10 Thread Dimitris Rizopoulos
you just need to use quotes, e.g., if (type == "Lower") { tL <- - tU <- qt(1-alpha,n-1) } and so on. I hope it helps. Best, Dimitris Mary A. Marion wrote: Hello, I am working on using if statements. What is the error message telling me here and how do I correct for it? I have

Re: [R] IF STATEMENTS

2009-07-10 Thread Bert Gunter
-help@r-project.org Subject: Re: [R] IF STATEMENTS you just need to use quotes, e.g., if (type == "Lower") { tL <- - tU <- qt(1-alpha,n-1) } and so on. I hope it helps. Best, Dimitris Mary A. Marion wrote: > Hello, > > I am working on using if statements. W

Re: [R] IF STATEMENTS

2009-07-10 Thread Godmar Back
It thinks twoSided is a variable, but you've never assigned such a variable. Use "twoSided" instead - that's a string constant. On Fri, Jul 10, 2009 at 4:04 PM, Mary A. Marion wrote: > Hello, > > I am working on using if statements.  What  is the error message telling me > here and how do I correc

[R] IF STATEMENTS

2009-07-10 Thread Mary A. Marion
Hello, I am working on using if statements. What is the error message telling me here and how do I correct for it? I have tried various combinations of quotes. Thank you. Sincerely, Mary A. Marion #Find critical values crit<-function(n,alpha,type) { if (type==twoSided) { alpha2=alpha/2 tL<

Re: [R] If statements for vectors

2008-04-09 Thread Vincent Goulet
Le mer. 9 avr. à 18:00, Paul Johnson a écrit : > On Wed, Apr 9, 2008 at 4:07 PM, Laura Bonnett <[EMAIL PROTECTED] > > wrote: >> Dear Sirs, >> >> I am using both the Bioconductor adds on (Affy, AffyPLM,...) and the >> 'standard' R-package. >> >> I am trying to select a list of genes which all have

Re: [R] If statements for vectors

2008-04-09 Thread Paul Johnson
On Wed, Apr 9, 2008 at 4:07 PM, Laura Bonnett <[EMAIL PROTECTED]> wrote: > Dear Sirs, > > I am using both the Bioconductor adds on (Affy, AffyPLM,...) and the > 'standard' R-package. > > I am trying to select a list of genes which all have expression values below > a certain threshold. > I hav

[R] If statements for vectors

2008-04-09 Thread Laura Bonnett
Dear Sirs, I am using both the Bioconductor adds on (Affy, AffyPLM,...) and the 'standard' R-package. I am trying to select a list of genes which all have expression values below a certain threshold. I have done this by creating a vector which has 0s where the expression is greater than the thres