[R] Help with loop ;(
arun
smartpink111 at yahoo.com
Wed Oct 23 00:57:43 CEST 2013
Hi,
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")
res
}
vec1 <- 1:10
vec2 <- 11:20
vec3 <- 1:9
vec4 <- 10:18
fun1(vec3,vec4)
fun1(vec1,vec2)
fun1(vec1,vec3)
A.K.
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