I have a file format like this
data<-mtcars[,c("mpg","drat","wt")]
data<- tibble::rownames_to_column(data, "Names")
I need to sort (Ascending) all the columns and filter to the top 50 %. Then from this data, I need to get the common one. For this purpose, I am using the following code
mpg<-data %>% dplyr::select(Names,mpg)%>%mutate_if(is.numeric, round,digits=3) %>% arrange(desc(mpg))%>% filter(row_number() / n() <= .5)
drat<-data %>% dplyr::select(Names,drat)%>%mutate_if(is.numeric, round,digits=3) %>% arrange(desc(drat))%>% filter(row_number() / n() <= .5)
wt<-data %>% dplyr::select(Names,wt)%>%mutate_if(is.numeric, round,digits=3) %>% arrange(desc(wt))%>% filter(row_number() / n() <= .5)
The code above will sort and filter the top 50 percentage
join_all(list(mpg,drat,wt),by = 'Names', type = 'inner')
This will print the common in the top 50 percent from all columns.
Is there any way to do this via some package or function like a single line?