If i have the following table:
tibble(year = c("2020", "2020", "2020","2021", "2021", "2021"),
website = c("facebook", "google", "youtube","facebook", "google", "youtube"),
method = c("laptop", "laptop", "laptop", "mobile", "mobile", "mobile"),
values = c(10,30,60, 90,25, 40))
How can i try to go about creating a column based on a custom q-tile of the numbers in the value column.
For example, if i have the following custom q-tile conditions:
Risky - > 50% Neither - 25-50% Safe - <25%
These are basically saying for the numbers in the values column, calculate what their ranking based on the q-tile conditions above and give them a rank value of 1,2,3 accordingly.
The final table should look like this:
tibble(year = c("2020", "2020", "2020","2021", "2021", "2021"),
website = c("facebook", "google", "youtube","facebook", "google", "youtube"),
method = c("laptop", "laptop", "laptop", "mobile", "mobile", "mobile"),
values = c(10,30,60, 90,25, 40),
rank = c(3,2,1,1,3,2))
I know that the table will have to be grouped by year and method along, so the code will look like this:
df %>% group_by(year, method) %>% mutate(rank = quantile(???))