I have several species in a data frame (df) and I need to add info of their corresponding taxonomic family, which I have downloaded and have in a second dataframe (sacc), which is a larger dataframe.
I've tried this for loop, but it doesn't work. It should compare genus from both dataframes and identify equal genera. then it should put the family (sacc) data into my dataframe (df).
for (i in length(df$genus)){
if (identical(sacc$Genus[i], df$genus[i])) {
df$family[i] <- sacc$Family[i]
} else {
i-1
}
print(df$family)
}
the output shows that somehow it is comparing strings, but the families are not assigned following the "if" condition.
print(df$family)
[1] "Rheidae" "Rheidae" "Tinamidae" "Tinamidae" "Tinamidae" "Tinamidae"
[7] "Tinamidae" "Tinamidae" "Tinamidae" "Tinamidae" "Tinamidae" "Tinamidae"
[13] "Tinamidae" "Tinamidae" "Tinamidae" "Tinamidae" "Tinamidae" "Tinamidae"
[19] "Tinamidae" "Tinamidae" "Tinamidae" "Tinamidae" "Tinamidae" "Tinamidae"
[25] "Tinamidae" "Tinamidae" "Tinamidae" "Tinamidae" "Tinamidae" "Tinamidae"
[31] "Tinamidae" "Tinamidae" "Tinamidae" "Tinamidae" "Tinamidae" "Tinamidae"
[37] "Tinamidae" "Tinamidae" "Tinamidae" "Tinamidae" "Tinamidae" "Tinamidae"
[43] "Tinamidae" "Tinamidae" "Tinamidae" "Tinamidae"
Help!
Aucun commentaire:
Enregistrer un commentaire