How do I drop variables that contain certain words e.g. "ERROR1" or "ERROR1" or both? I am looking for a general solution. Thanks in advance!
library(tidyverse)
toy_data <- tibble(
year = rep(2010:2011, each = 4),
cat = rep(c("A", "B", "C", "D"), times = 2),
i = rnorm(8),
k = c(rnorm(7), "ERROR1"),
l = c(rnorm(7), "ERROR2"),
m = c("ERROR1", "ERROR2", rnorm(6))
)
toy_data
#> # A tibble: 8 x 6
#> year cat i k l m
#> <int> <chr> <dbl> <chr> <chr> <chr>
#> 1 2010 A -0.255 0.17487171060379 0.53752746125903 ERROR1
#> 2 2010 B 0.947 2.20960747642375 -1.07459398632459 ERROR2
#> 3 2010 C 0.402 0.331472426766173 -1.26145314640879 0.109379293657667
#> 4 2010 D 0.764 -0.257007016841951 -0.51664541999114 -0.634155097786941
#> 5 2011 A -1.02 1.54227000076291 2.42946294561708 -0.0146312521180938
#> 6 2011 B 1.11 -0.666488302277402 0.354761773034822 0.0051401757579631
#> 7 2011 C -1.44 0.738880132017502 0.834126780022647 -1.39864301101319
#> 8 2011 D -1.09 ERROR1 ERROR2 0.53178497895577
Created on 2020-08-04 by the reprex package (v0.3.0)