Q:

filter columns of a dataframe based on a vector

I have a dataframe with multiple columns, to which I calculate the median by column and then filter by the rows that are greater than its median. My question is there is some way to create a shorter code.
Note: The filter I need always meets the condition for Xi> xi.
set.seed(123)
df = data.frame(replicate(10,sample(1:10,1000,rep=TRUE)))
x <- sapply(df,median)
library(dplyr)
filter(df, X1 > x[1], X2 > x[2], X3 > x[3], X4 > x[4], X5  > x[5], 
           X6 > x[6], X7 > x[7], X8 > x[8], X9 > x[9], X10 > x[10])

Expected output
  X1 X2 X3 X4 X5 X6 X7 X8 X9 X10
1  8 10  7  9  8  6 10  8  8   9

A:

Here's one way -
filter(df, apply(df, 1, function(a) all(a > x)))

  X1 X2 X3 X4 X5 X6 X7 X8 X9 X10
1  8 10  7  9  8  6 10  8  8   9

