Suppose I have data such as

tmp <- data.frame(score = c(1,2,3,4, 4,3,2,1), trial = gl(2,4), Gender = 
gl(2,2,8, labels=c('M', 'F')))

Now I would like to compute a rank on the variable score conditional on trial 
and gender. I could do

res <- with(tmp, tapply(score, list(Gender, trial), rank))
res[,1]
res[,2]

and then finagle a way to create a new variable in the dataframe tmp that has 
these ranks associated with the correct rows. But, perhaps there is a better 
way. Any suggestions?

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to