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 && trend1== -1) {position <- 1} else {position <- 0} based on this two conditions, the position vector should have a value: position: 1,1,1,1,1,1,0,0,0,0,0,0 Is there a way to do this in R without explicitly going through a for loop? The if condition doesn't work as it only accept one condition (aka no vectors). [[alternative HTML version deleted]] ______________________________________________ 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/posting-guide.html and provide commented, minimal, self-contained, reproducible code.