I have a data frame:
mydata <- data.frame(
x1= as.factor(1:3),
x2= as.factor (4:6),
x3= as.factor(7:9),
x4= as.factor (2:7),
x5= as.factor(1:6),
x6= seq(0,600,len= 600),
x7= seq(0,1,len=600)
)
And I want to remove some rows in this with particular conditions. I did it this way:
mydata1 <- mydata%>%
filter(x1==1, x2==4, x3==7, x4==2, x5==1)%>%
anti_join(mydata,., by=c("x1", "x2", "x3", "x4","x5","x6" "x7"))
mydata2 <- mydata1%>%
filter(x1==3, x2==6 x3==9, x4==7, x5==6)%>%
anti_join(mydata1,., by=c("x1", "x2", "x3", "x4","x5","x6", "x7"))
There are a lot of rows that I want to remove. Is there another way to do this?
mydata1 <- mydata[!as.character(interaction(mydata[1:5])) %in% "1.4.7.2.1",];mydata2 <- mydata1[!as.character(interaction(mydata1[1:5])) %in% "1.6.9.7.6",]