You don't need temporary variable x

c<-f(1,2)[[1]]
d<-f(1,2)[[2]]

Weidong Gu

On Fri, Mar 30, 2012 at 6:40 PM, ivo welch <ivo...@gmail.com> wrote:
> Dear R wizards:  is there a clean way to assign to elements in a list?
>  what I would like to do, in pseudo R+perl notation is
>
>  f <- function(a,b) list(a+b,a-b)
>  (c,d) <- f(1,2)
>
> and have c be assigned 1+2 and d be assigned 1-2.  right now, I use the clunky
>
>  x <- f(1,2)
>  c <- x[[1]]
>  d <- x[[2]]
>  rm(x)
>
> which seems awful.  is there a nicer syntax?
>
> regards, /iaw
> ----
> Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com)
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to