Hello !
I have a question regarding the IF function.
Here is my table, I would like in column D to have the same thing as in column C except that I would like to replace the "Unidentified" by the closest known taxonomic resolution as the example below:
Here for the first line Unidentified (column C) is replaced by Mycto because it is the closest known taxo resolution. On the other hand, for the 3rd line, the closest known taxo resolution is in column B, so Bra.
What would be the formula to enter in column D to have this kind of results?
Thanks very much !
Replace "Unidentified" by NA everywhere and then use coalesce from dplyr package.
e.g.
library(tidyverse)
df <- tribble(
~A, ~B, ~C, ~D,
"Mycto",NA,NA,NA,
"Mact", "Prio", "Boreo", NA,
"Lui", "Bra",NA, NA
)
df %>% mutate(D = coalesce(C,B,A))
#> # A tibble: 3 × 4
#> A B C D
#> <chr> <chr> <chr> <chr>
#> 1 Mycto <NA> <NA> Mycto
#> 2 Mact Prio Boreo Boreo
#> 3 Lui Bra <NA> Bra
Created on 2022-05-06 by the reprex package (v2.0.1)