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