In my project I wanted to extract a row from a dataframe if both of the column Var1&Var2 has the same value as requested. Is there any functions that can do that? I've tried to use which() but it doesn't work.
what I tried:
x<-5
y<-3
p1<-Data[which(x1 == Data$Var1 & x2 == Data$Var2), ]
Basically I want to have row extracted if the value of x and y is the same with Var1 and Var2.
Thanks !!
CodePudding user response:
I think you are looking for filter()
which is used to:
Return rows with matching conditions
See documentation here
CodePudding user response:
you can try as mentioned in the first answer as follows
library(tidyverse)
x=5
y=6
p1 <- filter(Data, (var1==x & var2==y))