[R] Dismiss previous email

Judith Flores juryef at yahoo.com
Sat Dec 1 02:44:03 CET 2007


Sorry about that, it was sent by accident.

I have a data frame that looks something like this:

   id day    k
  56  -1  566
  63  -1  680
  73  -1  773
  56   2  298
  63   2  273
  
    Of course, it is a very simplified version of the
real data frame I am working on. I need to add another
column that would represent a percent change in k from
day -1, by id. I put only two ids at day 2 to
emphasize the fact that after day -1 some subjects
won't be on the data frame any more.

I tried something like this:

pck<-by(dat,dat[,c("id","day")], function(x) {
      pc<-((x$k-x$k[x$day==-1])/x$k[x$day==-1])*100
      })
but it didn't work. 

Then I tried:

for(i in dat$id) {

    for(s in dat$day) {
        pc<-((dat$k[dat$id==i &
dat$day==s]-dat$k[dat$id==i &
dat$day==-1])/dat$k[dat$id==i & dat$day==-1])*100
}
}
without success.

I am sure it is very simple to do, but I would
appreciate any hints.

Thank you,

Judith



 


      ____________________________________________________________________________________
Be a better pen pal.



More information about the R-help mailing list