Reputation: 463
I would like to filter out all columns where the value in row "b" is >2% of the sum of all rows in a given column.
df
x y z
a 99 95 99
b 1 4 1
c 0 1 0
result
x z
a 99 99
b 1 1
c 0 0
Upvotes: 0
Views: 71
Reputation: 56054
Try this:
df1[, df1["b", ]/colSums(df1) <= 0.02 ]
# x z
# a 99 99
# b 1 1
# c 0 0
Upvotes: 3