Re: [R] Finding a mean value of a variable holding a dummy variablefixed

2008-03-30 Thread Daniel Malter
The mean problem can be solved with president=c(Johnson,Johnson,Johnson,Johnson,Johnson,Johnson,Nix on,Nixon,Nixon,Nixon,Nixon,Nixon) approval=seq(1:12) tapply(approval,president,mean) For the other, I will try to come back. But I am sure somebody will be faster than I. Cheers, Daniel

Re: [R] Finding a mean value of a variable holding a dummy variablefixed

2008-03-30 Thread Daniel Malter
I found a solution. It's probably not the easiest one, but it works. It assumes that your data frame is ordered from earliest to latest record for each president, but it can be easily adjusted if you want to make it dependent on a third column. The final vector index gives you the line indices