[R] Help with apply()
    Jim Lemon 
    jim at bitwrit.com.au
       
    Mon Feb  8 07:33:41 CET 2010
    
    
  
On 02/08/2010 12:26 PM, Nathan S. Watson-Haigh wrote:
> 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().
>
Hi Nathan,
apply doesn't work with data frames unless they can be coerced to 
matrices or arrays (and sometimes not even then). What's wrong with 
using the code you have above?
Jim
    
    
More information about the R-help
mailing list