"could not find function" for a data.frame element

Hi Tom, welcome!

You are using the wrong function, you can't use tidyselect functions to check for text inside variables, try using stringr functions instead, see this example:

library(dplyr)
library(stringr)

mature_trees <- data.frame(stringsAsFactors=FALSE,
           Plot.ID = c("0181E", "0181E", "0181D", "0181D"),
           Tag.number = c(1L, 2L, 3L, 4L),
           Species = c("PIAB", "ACRU", "PIAB", "PIAB"),
           Year = c(2017L, 2017L, 2017L, 2017L),
           D_2017 = c(15.2, 25, 8.5, 11.8),
           D_2018 = c(15.8, 25.9, 8.5, 11.9),
           D_2019 = c(15.6, 25.9, 9.5, 12)
)

mature_trees %>% 
    mutate(plot_type = case_when(str_detect(Plot.ID, "D$")~'Decidious',
                                 str_detect(Plot.ID, "E$")~'Evergreen',
                                 TRUE~"NA"))
#>   Plot.ID Tag.number Species Year D_2017 D_2018 D_2019 plot_type
#> 1   0181E          1    PIAB 2017   15.2   15.8   15.6 Evergreen
#> 2   0181E          2    ACRU 2017   25.0   25.9   25.9 Evergreen
#> 3   0181D          3    PIAB 2017    8.5    8.5    9.5 Decidious
#> 4   0181D          4    PIAB 2017   11.8   11.9   12.0 Decidious

Created on 2019-09-23 by the reprex package (v0.3.0.9000)

Note: For future posts, please provide a proper REPRoducible EXample (reprex) like the shown above.

2 Likes