Here's something odd that the apply functions are doing and I'm wondering if anyone can explain this to me.
If I run the following:
namer <- function(x, y) {
print(paste0("x is ", x))
print(paste0("y is ", y))
}
sapply(c(1,2,3), FUN = namer, y = 100)
It outputs:
[1] "x is 1"
[1] "y is 100"
[1] "x is 2"
[1] "y is 100"
[1] "x is 3"
[1] "y is 100"
[1] "y is 100" "y is 100" "y is 100"
Why that last row, which seems to run through the function as many times as I provided x inputs, but only outputting the y input (and all as one row)? This makes working with the output a bit tricky since I will need to somehow omit the final row each time.
Thanks.