0

I have a dataframe:

x<-c(10,80,30,40,50,10,20,80,90,100)
y<-c(15,10,35,45,90,65,75,85,80,90)
E<-seq(1,10,by=1)

data <- data.frame(x,y,E)

From this data i want to extract a sub - dataframe data1, that is included in data:

x1<-c(10,80)
y1<-c(15,85)
E1<-c(1,8)
data1<-data.frame(x1,y1,E1)
names(data1)<-c("x","y","E")

and I want to get the residual data frame (data - data1).

I prefer something that use x and y values to get the residual df, and if it's possible, a generally use code, without blocking the position of the data rows.

Lince202
  • 143
  • 10

1 Answers1

1

If I understand correctly the question, the desired output is a dataframe that contains all the rows of data but not the rows in data1. You can do that anti-joining the 2 dataframes:

library(dplyr)
anti_join(data, data1)

Note that this will return the rows in different order from the original dataframe. If this is a problem you can do:

library(dplyr)
anti_join(mutate(data, ID = row_number()), data1) %>% arrange(ID)
Lorenzo Rossi
  • 1,481
  • 1
  • 9
  • 16