I have a dataframe like this:
Family | Genus | Species |
---|---|---|
Gemmatimonadaceae | Roseisolibacter | Roseisolibacter_agri |
Bacillaceae | Bacillus | NA |
Blastocatellaceae | NA | NA |
And I would like to modify it as follow:
Family | Genus | Species |
---|---|---|
Gemmatimonadaceae | Roseisolibacter | Roseisolibacter_agri |
Bacillaceae | Bacillus | Unclassified Bacillus |
Blastocatellaceae | Unclassified Blastocallaceae | Unclassified Blastocallaceae |
I was trying to do this:
replace_na(
list(Genus = paste("Unclassified", Family),
Species = paste("Unclassified", Genus)))
or using
replace_na(
list(Genus = paste("Unclassified", vars(Family)),
Species = paste("Unclassified", vars(Genus))))
But in both cases I end up with "Unclassified Genus" or "Unclassified ~Genus".
How can I make it inherit from the previous known variable?
I thought also of using fill()
but it works for tidy data only. Naturally I could transpose the data.frame but there must be a more elegant/simple solution!