There's lots of advice for how to calculate quantiles for a column of data, but I'm trying to label each data point with which quantile it belongs to based on some other field.
A super simple example:
pink<-data.frame(matrix(rnorm(20),nrow=100))
pink$color<-c("pink")
red<-data.frame(matrix(rnorm(50),nrow=100))
red$color<-c("red")
names(red)[names(red)=="matrix.rnorm.50...nrow...100."]<-"value"
names(pink)[names(pink)=="matrix.rnorm.20...nrow...100."]<-"value"
mydata<-rbind(red,pink)
So imagine all I have is the mydata data frame. I want a new column that assigns each row to a quantile based on the $value for the $color. In the case above, a row that has a value of 0.7 is going to be in the top quartile for pink but it wouldn't be for red.
How do I do this kind of "quantile by group/factor"? Thanks for any help!