[R] help in vectorization
Gabor Grothendieck
ggrothendieck at gmail.com
Wed Jul 12 06:25:32 CEST 2006
Try this:
with(merge(dtf, dtf2), data.frame(y, m, inc = inc/def))
On 7/11/06, Dimitri Szerman <dimitrijoe at ipea.gov.br> wrote:
> Hi,
>
> I have two data frames. One is like
>
> > dtf = data.frame(y=c(rep(2002,4), rep(2003,5)),
> + m=c(9:12, 1:5),
> + def=c(.74,.75,.76,.78,.80,.82,.85,.85,.87))
>
> and the other
>
> dtf2 = data.frame(y=rep( c(2002,2003),20),
> m=c(trunc(runif(20,1,5)),trunc(runif(20,9,12))),
> inc=rnorm(40,mean=300,sd=150) )
>
> What I want is to divide dtf2$inc by dtf1$def by the "levels" of y and m
> (inc is income and def is the deflator). Any help in vectorizing this is
> welcome.
>
> Thank you,
> Dimitri
More information about the R-help
mailing list