Ntile and decile function depended on two columns in R [duplicate]
问题 This question already has answers here : Aggregate / summarize multiple variables per group (e.g. sum, mean) (6 answers) Closed 11 months ago . I would like to have a new column with Ntile but it should depend on column 1 - "year" and show the ntile number for column 2 - "mileage". year mileage <dbl> <dbl> 1 2011 7413 2 2011 10926 3 2011 7351 4 2011 11613 5 2012 8367 6 2010 25125 mydata$Ntile <- ntile(mydata$mileage, 10) I know the easy to use function ntile , but I do not know how to make it