0 votes
1 view
in R Programming by (12.5k points)

a  b

1 30

1 10

1  8

2 10

2 18

2  5

I have this data-set with me, where column 'a' is of factor type with levels '1' and '2'. Column 'b' has random whole numbers. Now, i would want to filter this data-frame such that i only get values more than 15 from 'b' column where 'a=1' and get values greater 5 from 'b' where 'a==2'

So, i would want the output to be like this:

a b

1 30

2 10

2 18

1 Answer

0 votes
by (32.8k points)

You can use the 'filter' function from 'dplyr' package to solve this:

library(dplyr)

filter(df, (a==1 & b>15) | (a==2 & b>5))

Hope this answer helps you!

...