Re: [R] A question on function return

2013-03-22 Thread Peter Ehlers
On 2013-03-22 11:43, Christofer Bogaso wrote: 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

Re: [R] A question on function return

2013-03-22 Thread Rui Barradas
Hello, You get only one value because ifelse is vectorized, and the condition has length(x > 0) == 1. (You get as many values as there are in the condition.) Try instead fn2 <- function(x, y) { Vec1 <- letters[1:6] Vec2 <- 1:5 list(if(x > 0) Vec1 else NA, if(y > 0) Ve

[R] A question on function return

2013-03-22 Thread Christofer Bogaso
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: > fn(-3, -3) [[1]] [1]