The reason your solution didn't work is that the x
being passed to your user-defined function is actually a column of df
. Therefore, you could get your solution working with a small modification (replacing df[[x]]
with x
):
apply(df[2:10], 2, function(x) df[abs(x)>0.32, 1])
You could use the ...
argument to apply
to pass an extra argument. In this case, you would want to pass the first column:
apply(df[2:10], 2, function(x, y) y[abs(x) > 0.32], y=df[,1])