[R] Return value from function with For loop
Ramnik Bansal
ramnik.bansal at gmail.com
Mon Apr 17 04:26:04 CEST 2017
In the code below
*ff <- function(n){ for(i in 1:n) (i+1)}*
*n<-3;ff(n)->op;print(op)*
Why doesnt *print(op) * print 4 and instead prints NULL.
Isnt the last line of code executed is *i+1 * and therefore that should be
returned instead of NULL
instead if I say
*ff <- function(n){ (n+1) }*
Then
*n<-3;ff(n)->op;rm(n);print(op)*
gives 4 as output.
My question is *Which *is considered as the last line in a functoin for the
purpsoe of default return ? And under what conditions ?
-Thanks,
Ramnik
[[alternative HTML version deleted]]
More information about the R-help
mailing list