I have a several groups, let's say A,B,C and I want to cut
another variable based on these groups, i.e. each group has specific breaks for the same variable.
If I had to calculate the groups mean, i´d use tapply
like this:
tapply(mydata$var,mydata$group,mean)
Unfortunately I do not know how to fix this for cut
with changing breaks=c(...) arguments for different groups.
tapply(mydata$var,mydata$group,cut)
Any suggestions? I´d like to do it with tapply
but any other solution but a custom made function would be suitable too.
EDIT: some small example:
test <- data.frame(var=rnorm(100,0,1),
group=c(rep("A",30),
rep("B",20),
rep("C",50)))
# for group A:
cut(test$var,breaks=c(-4,0,4))
# for group B
cut(test$var,breaks=c(-4,1,4))
and so on...