[R] style question: returning multiple arguments - structure orlist

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Sat Jul 28 23:23:48 CEST 2001


"Thomas J Vogels" <tov at ece.cmu.edu> writes:

> Hi,
> 
> you also have the option of "throwing out" the third result by setting it to
> NULL (taking your LIST option)?
> 
> > f <- function() {
> >   ...
> >   list(x=x,y=y,z=z)
> > }
> > res <- f()
> > names(jj)
> [1] "x" "y" "z"
> > res$z <- NULL
> > names(res)
> [1] "x" "y"
> 
> and then work with res (res$x and res$y)?

A little summer exercise: Can one write a list assignment function,
i.e. "list<-" so that

list(a,b,c) <- f()

would be equivalent to

r <- f()
a <- r[[1]]
b <- r[[2]]
c <- r[[3]]

Even better, do something useful with named list elements. (And what
are the odds of finding that this is really an exercise hidden
somewhere in a book by Venables and Ripley?)

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list