r - Subsetting a data frame when values in two columns match those in a second data frame -
I have two big data frames DF1 has two column interest (among the other), these species of A1 There is a list of names and list of 3 letter areas in A2. Each line is an independent record, so can be repeated several times in both columns, and there are several rows (~ 9 million):
A1A 2 species is an AZ Species B species My second data frame (DF2) essentially lists every field that should be within a species, so for each value B1, there will be a number of B2B2 species A A Castes Aflo species B vaccine species B PLA species C THA
What do I want to do, the values given in A2 (DF1) using R2 For each species, standards are standardized in B2 (DF2). Therefore, for each line in DF1, if the value in A1 is equal to B1, similar to and A2b2 (if A1 == B1 and A2 == B2), the row So in my example above, line 2 will be removed from DF1.
I have tried the following, but no success (no row has been removed):
x
Any suggestions? Will the match function be more suitable?
This is also the first question I have asked on the stack overflow - I am not sorry if it is not great - any comments are welcome to improve the question! >
Cheers!
You can use
merge to do this just right < Code> by.x and
by.y logic. Here's an example of how to do this:
# Your data df1 & lt; - read.table (text = "A1A 2 species_Afg speciesGbA species _bop species THA", header = TRUE) DF2 & lt; - read.table (text = "B1b2 species _a azg species _ aflo species _lop species species pla species _ tha", header = TRUE) # merged data. Frames merges (df1, df2 [, c ( "B1", "B2"), By.x = c ("A1", "A2"), by.y = c ("B1", "B2"))
Comments
Post a Comment