Skip to content
Prev 320125 / 398502 Next

A question on function return

Hello again,

Let say I have following user defined function:

fn <- function(x, y) {
		Vec1 <- letters[1:6]
		Vec2 <- 1:5
		return(list(ifelse(x > 0, Vec1, NA), ifelse(y > 0, Vec2, NA)))
	}

Now I have following calculation:
[[1]]
[1] NA

[[2]]
[1] NA
[[1]]
[1] "a"

[[2]]
[1] NA


Here I can not understand why in the second case, I get only the first
element "a" of the corresponding vector 'Vec1'? I want to get complete
vector(s) as the function return.

Can somebody help me how to achieve that?

Thanks and regards,