[R] Basic question on applying a function to each row of a dataframe

peter leonard pfleonard at hotmail.com
Tue Jun 10 02:05:17 CEST 2003


This works fine. Thanks everybody for all your help,

Peter



>From: Thomas Lumley <tlumley at u.washington.edu>
>To: peter leonard <pfleonard at hotmail.com>
>CC: r-help at stat.math.ethz.ch
>Subject: Re: [R] Basic question on applying a function to each row of a 
>dataframe Date: Mon, 9 Jun 2003 06:47:20 -0700 (PDT)
>
>On Sun, 8 Jun 2003, peter leonard wrote:
>
> > Hi,
> >
> > I have a function foo(x,y) and a dataframe, DF,  comprised of two 
>vectors, x
> > & w,  as follows :
> >
> >    x w
> > 1  1 1
> > 2  2 1
> > 3  3 1
> > 4  4 1
> >
> > etc
> >
> >
> > I would like to apply the function foo to each 'pair' within DF e.g
> > foo(1,1), foo(2,1), foo(3,1) etc
> >
>
>In R 1.7.0 there is a function mapply() for this sort of thing.
>
>mapply("foo",DF[,1],DF[,2])
>
>	-thomas
>




More information about the R-help mailing list