[R] Help with apply()

Nathan S. Watson-Haigh nathan.watson-haigh at csiro.au
Mon Feb 8 02:26:28 CET 2010


I have a 2 column data.frame:

 > d[1:5,]
   a b
1    80015     C
2    80016     B
3    80023     C
4    80062     B
5    80069     B

I want to apply a function across each row:

 > for(i in 1:nrow(d)) {
+    myFun(con, d[i,]$a, d[i,]$b)
+ }

How do I do this using apply()? I'm unsure how to tell apply() to pass 
data from columns a and b for a given row as arguments to the function 
myFun().

Thanks in advance for any pointers,
Nathan

-- 
--------------------------------------------------------
Dr. Nathan S. Watson-Haigh
OCE Post Doctoral Fellow
CSIRO Livestock Industries
University Drive
Townsville, QLD 4810
Australia

Tel: +61 (0)7 4753 8548
Fax: +61 (0)7 4753 8600
Web: http://www.csiro.au/people/Nathan.Watson-Haigh.html



More information about the R-help mailing list