I'm trying to subset a dataframe on the basis of conditions from multiple columns. Here is my dataframe.
var1 <- c(x,x,x,y,y,z,z,z,z)
var2 <- c(a,b,c,a,b,a,b,c,d)
var3 <- c(2,4,1,4,1,6,2,5,8)
data1 <- data.frame(var1,var2,var3)
# -------------------------------------------------------------------------
# var1 var2 var3
# 1 x a 2
# 2 x b 4
# 3 x c 1
# 4 y a 4
# 5 y b 1
# 6 z a 6
# 7 z b 2
# 8 z c 5
# 9 z d 8
Output
The output I expect is:
# var1
# 1 y
# 2 z
Condition
The following are the conditions leading to the output:
- The output is a dataframe where only values of
var1
are selected.- Values of
var3
wherevar2
is equal toa
is greater than values ofvar3
wherevar2
is equal tob
.
I'm unable to create a code based on this complicated condition from multiple columns.
Thank you.