Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (19k 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 (33.1k 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!

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...