[R] calling pairs of variables into a function

rex.dwyer at syngenta.com rex.dwyer at syngenta.com
Thu Feb 17 17:46:18 CET 2011


Try putting d,e,f in a list:
Xxx = list(d,e,f)

For (I in 1:length(xxx))
For (j in 1:length(xxx))
If (i!=j) bigfunction(xxx[[i]],xxx[[j]])

(bad indentation, caps thanks to outlook)


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of squamous
Sent: Wednesday, February 16, 2011 7:11 PM
To: r-help at r-project.org
Subject: [R] calling pairs of variables into a function


Hi,
I have imported three text files into R using read.table.  Their variables
are called d, e and f.

I want to run a function on all the possible combinations of these three
files.  The only way I know how to do that is like this:

bigfunction(d,e)
bigfunction(d,f)
bigfunction(e,d)
bigfunction(e,f)
bigfunction(f,e)
bigfunction(f,d)

Is there an easier way?  I will have five files later on, so it would be
useful to know!  I'd imagine I can use a loop somehow, and I have installed
a package (gregmisc) so that typing permutations(3,2) gives all the possible
pairs of three numbers, but I don't know how to combine these things to make
it work.
--
View this message in context: http://r.789695.n4.nabble.com/calling-pairs-of-variables-into-a-function-tp3309993p3309993.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at 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.




message may contain confidential information. If you are not the designated recipient, please notify the sender immediately, and delete the original and any copies. Any use of the message by you is prohibited. 


More information about the R-help mailing list