Displaying 3 results from an estimated 3 matches for "miscell".
2009 Mar 22
5
If statement generates two outputs
Hi,
How do I tell an if statement to generate two seperate outputs.
E.g If X>5 I want to create df1 and df2:
if (X>5) {df1<-c(4,5,6,7,8) AND df2<-c(9,10,11,12,13)}
Thanks,
James
--
View this message in context: http://www.nabble.com/If-statement-generates-two-outputs-tp22650844p22650844.html
Sent from the R help mailing list archive at Nabble.com.
2009 Jul 09
5
Best way to export values from a function?
Maybe there is a great website out there or white paper that discusses this but again my Google skills (or lack there of) let me down.
I would like to know the best way to export several doubles from a function, where the doubles are not an array.
Here is a contrived function similar to my needs:
multipleoutput<-function(x)
{
squared<-x^2
cubed<-x^3
exponentioal<-exp(x)
2009 Jul 09
2
How to Populate List
...on how to do this the
"normal" R way, so let's go ahead and use the "return a list" method
(I think it's better than using the `c(squared=x^2, cubed=...)`).
Here's an interesting way to receive the assignments. Check out this
function:
http://code.google.com/p/miscell/source/browse/rvalues/rvalues.r
With that ':=' function loaded, you could do this:
============
multipleout <- function(x) {
list(squared=x^2, cubed=x^3, exponential=exp(x),
factorial=factorial(x))
}
c(sq,cu,ex,fa) := multipleout(1:3)
show(sq)
[1] 1 4 9
show(cu)
[1] 1 8...