Let's suppose I have this dataset (not the original data I am using)
data <- data.frame(
name=c( rep("A",500), rep("B",500), rep("B",500), rep("C",20), rep('D', 100) ),
value=c( rnorm(500, 10, 5), rnorm(500, 13, 1), rnorm(500, 18, 1), rnorm(20, 25, 4), rnorm(100, 12, 1) )
)
I would like my code to
- group name
- arrange value in a descending way
- and select the top 30% but not by the value of my value variable, but the number of rows for each name
My code starts like this:
data <- data %>%
arrange(name, value) %>%
I read about top_frac() but as far as I understand it this selects the top x percent of the values.
Thanks in advance!