[R] function return output
David Winsemius
dwinsemius at comcast.net
Fri Jan 16 14:09:49 CET 2009
On Jan 16, 2009, at 5:22 AM, threshold wrote:
>
> Hi, I wrote the function which outputs a matrix 'c' and a single
> value 'd',
> as follows (simplified example):
> procedure <- function(a,b){
> ...
> list(c,d)
> }
> now I want to use 'c' and 'd' in code as follows:
> d <- matrix(0,1,1)
> value <- procedure(a,b)
> and d[1,1] <- value[2] breaks telling that:
> Error in d[1, 1] : incorrect number of dimensions
> What I did wrong??, best, robert
Who knows? No reproducible code.
The usual way of accessing just the second element of a list would be
value[[2]]. value[2] will be a list that contains whatever was "d",
rather than what was "d" in the procedure() call itself. It will not
have the name "d". It is possible to use the same names inside and
outside a function but it may be more clear for beginners to keep them
separate.
--
David Winsemius
More information about the R-help
mailing list