Explore Courses Blog Tutorials Interview Questions
0 votes
in R Programming by (50.2k points)
In R, I am having a matrix of numeric values and want to display only the highest 20% of a specific column. How to perform that?

1 Answer

0 votes
by (108k points)

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) %>%

    top_frac(n = 0.2, wt = col1)

Or you can use the slice_max %>%

     slice_max(col1, prop = 0.2)

Browse Categories