Hello!
I am trying to imitate the Index(Match() function in Excel. Basically what has happened is this:
- I had this initial dataframe:
dput(EFR.ex, 10)
structure(list(Density_cells_per_mL = c(40477.29429, 919.9385066,
22998.46266, 32197.84773, 919.9385066, 16098.92387, 505.8492373,
919.9385066, 71755.20351, 919.9385066), Algal_Group = c("Cyanobacteria",
"Green Algae", "Cyanobacteria", "Cyanobacteria", "Green Algae",
"Green Algae", "Green Algae", "Cyanobacteria", "Cyanobacteria",
"Haptophytes"), Genus = c("Anabaena", "Ankistrodesmus", "Aphanizomenon",
"Aphanocapsa", "Chlamydomonas", "Chlorella", "Chlorogonium",
"Chroococcus", "Chroococcus", "Chrysochromulina")), row.names = c(NA,
10L), class = "data.frame")
- I aggregated some algal densities, which created a new data frame. I then used this aggregated information to create an NMDS plot in R and associated the species with the ordination points to get this data frame:
dput(head(species.scores,10))
structure(list(NMDS1 = c(-0.0658985027506765, -0.1057693049412,
0.0414392803242683, -0.131625100961953, -0.126438528647588, 0.10738777684384,
-0.018071066906765, 0.0617902321086005, 0.0438645773084015, -0.1619003291023
), NMDS2 = c(-0.0213016404546824, 0.0418361050301208, 0.0338151840015218,
-0.104557880312153, 0.026295743677768, -0.0268381946290351, 0.0935447463941724,
-0.0275020026132876, -0.0160527011087588, 0.0107856144200736),
species = c("Actinastrum", "Anabaena", "Ankistrodesmus",
"Aphanizomenon", "Aphanocapsa", "Carteria", "Ceratium", "Chlamydomonas",
"Chlorella", "Chlorogonium")), row.names = c("Actinastrum",
"Anabaena", "Ankistrodesmus", "Aphanizomenon", "Aphanocapsa",
"Carteria", "Ceratium", "Chlamydomonas", "Chlorella", "Chlorogonium"
), class = "data.frame")
- What I want to do is match the genus in the second data frame (species.scores) to the algal group in the first dataframe (EFR.ex) and create a column that returns that value, so that basically the second data frame now looks like this:
> dput(head(species.scores.2, 10))
structure(list(NA. = c("Actinastrum", "Anabaena", "Ankistrodesmus",
"Aphanizomenon", "Aphanocapsa", "Carteria", "Ceratium", "Chlamydomonas",
"Chlorella", "Chlorogonium"), NMDS1 = c(-0.0658985027506765,
-0.1057693049412, 0.0414392803242683, -0.131625100961953, -0.126438528647588,
0.10738777684384, -0.018071066906765, 0.0617902321086005, 0.0438645773084015,
-0.1619003291023), NMDS2 = c(-0.0213016404546824, 0.0418361050301208,
0.0338151840015218, -0.104557880312153, 0.026295743677768, -0.0268381946290351,
0.0935447463941724, -0.0275020026132876, -0.0160527011087588,
0.0107856144200736), Genus = c("Actinastrum", "Anabaena", "Ankistrodesmus",
"Aphanizomenon", "Aphanocapsa", "Carteria", "Ceratium", "Chlamydomonas",
"Chlorella", "Chlorogonium"), Algal_Group = c("Green Algae",
"Cyanobacteria", "Green Algae", "Cyanobacteria", "Cyanobacteria",
"Green Algae", "Dinoflagellates", "Green Algae", "Green Algae",
"Green Algae")), row.names = c(NA, 10L), class = "data.frame")
That second dataframe I obtained by pulling the data into Excel and doing an Index(Match() function with the first dataframe, but I want to be able to do it directly in R. I have done a lot of Google searches on this and tried numerous methods but I just can't figure out how to do it. Any help would be so greatly appreciated!
Thank you so much!