A.Coder
A.Coder

Reputation: 51

percent_rank function in dplyr

I'm trying to use the percent_rank function in dplyr to divide one of my variables to into 3 separate variables depending on where they fall in the percent rank. I have the dplyr function loaded but the console keeps telling me that it can't find the function.

My code looks like this:

 library(dplyr)
 high_val <- percent_rank(df$val1) <- 0.66

And then continues on for each variable I want to divide. 0.66 is the percentile for the high value I want to use (66%). Any ideas?

Upvotes: 1

Views: 3437

Answers (1)

neilfws
neilfws

Reputation: 33802

I think you want to calculate the rank, filter and pull the values into a vector. Assuming that you want values equal or greater than 0.66:

library(dplyr)
high_val <- df %>%
  mutate(Rank = percent_rank(val1)) %>%
  filter(Rank >= 0.66) %>%
  pull(val1)

Upvotes: 2

Related Questions