I am trying to understand the mapply function, but I don't get it. Lets suppose I want to multiply each element of a vector with each element of another vector like this:
a <- c(1,2)
b <- c(1,2,3)
for (i in a){
for (j in b){
print(i*j)
}
}
Return 1 2 3 2 4 6, thats what I want.
func <- function(x,y){
return (x*y)
}
mapply(func, a, b)
This however returns 1 4 3. Why does it not work?