[R] Help with loop ;(

arun smartpink111 at yahoo.com
Wed Oct 23 00:57:43 CEST 2013


The conditions are not very clear. For example, it is not mentioned whether vectors are of same length or not.  Assuming the former case:
fun1 <- function(x,y){
 if(length(x)==length(y) & length(x)%%2==0){
 res <- x+y
 else if(length(x)==length(y) & length(x)%%2==1){
 res <- abs(x-y)
else print("Lengths are not same")
 vec1 <- 1:10
 vec2 <- 11:20
 vec3 <- 1:9
 vec4 <- 10:18


Hi, I'm new on this forum, and I need some help with for loop. I have to write loop that will add two vectors, if they are even. Even if they 
are odd, it must subtract the two vectors.

More information about the R-help mailing list