Back
In R programming, you can use the quantile() to create a logical vector and extract the elements from the column:
m1[,1][m1[,1] >= quantile(m1[,1], 0.8)]
If it is a data.frame then in that case you can use top_frac:
library(dplyr)as.data.frame(m1) %>% top_frac(n = 0.2, wt = col1)
library(dplyr)
as.data.frame(m1) %>%
top_frac(n = 0.2, wt = col1)
Or you can use the slice_max
as.data.frame(m1) %>% slice_max(col1, prop = 0.2)
slice_max(col1, prop = 0.2)
31k questions
32.8k answers
501 comments
693 users