Re: [R] assign variables to function output

2015-04-17 Thread MacQueen, Don
I don't disagree with the other answers, but I'd like to talk about what I see as a more underlying issue. Generally speaking, functions return the value of the last expression within them. myfun <- function(x) { z <- sqrt(x) 2 } Then y <- myfun(7) assigns 2 to y because 2 was the last expr

Re: [R] assign variables to function output

2015-04-16 Thread Sergio Fonda
That's it ! Sorry for writing in a hurry, Merm! Il 16/apr/2015 14:14, "Jim Lemon" ha scritto: > Hi merm, > In case Sergio's message is a little cryptic: > > return_a_list<-function() { > a<-"First item of list" > b<-c(2,4,6,8) > c<-matrix(1:9,nrow=3) > return(list(a,b,c)) > } > > x<-return_a_

Re: [R] assign variables to function output

2015-04-16 Thread Jim Lemon
Hi merm, In case Sergio's message is a little cryptic: return_a_list<-function() { a<-"First item of list" b<-c(2,4,6,8) c<-matrix(1:9,nrow=3) return(list(a,b,c)) } x<-return_a_list() x Jim On Thu, Apr 16, 2015 at 7:21 PM, Sergio Fonda wrote: > Collect in a vector or dataframe or list the

Re: [R] assign variables to function output

2015-04-16 Thread Sergio Fonda
Collect in a vector or dataframe or list the variables of interest and output it. Il 16/apr/2015 10:57, "merm" ha scritto: > Hi! > > So I'm trying as the header suggests to assign the value(s) output by a > function to a variable, say 'y' > > Problem is from what I gather any variables introduced

[R] assign variables to function output

2015-04-16 Thread merm
Hi! So I'm trying as the header suggests to assign the value(s) output by a function to a variable, say 'y' Problem is from what I gather any variables introduced within the function are contained and the only output I can get is "return(value)" which is awkward to work with. Any suggestions? Ch