Hi there,
I am trying to filter out several variables and instead of copying and pasting a bunch, I want to create a function. Here's the function I created:
feat <- function(x){
v %>% filter(x=="Y")
}
However, whenever I enter in the column name for my data, like so:
veg <- feat(VEGETATION)
I get the following error:
Error: Problem with `filter()` input `..1`.
i Input `..1` is `x == "Y"`.
x object 'VEGETATION' not found
I'm assuming there must be some sort of syntax issue, but I can't figure out what it is. Googled the problem and not finding any answers. Any help would be greatly appreciated.
Here's a subset of my data:
v <- structure(list(SITE_ID = c("GBA20-10501", "GBA20-10506", "GBA20-10507",
"GBA20-10508", "GBA20-10509", "GBA20-10510"), VISIT_NO = c(1L,
1L, 1L, 1L, 1L, 1L), FILENAME = c("GBS20-10501_V1_20210613_A_01",
"GBS20-10506_V1_20210608_B_01", "GBS20-10507_V1_20210606_A_01",
"GBS20-10508_V1_20210606_B_01", "GBS20-10509_V1_20210613_B_01",
"GBS20-10510_V1_20210612_A_01"), VIDEO_QUALITY = c("GOOD", "GOOD",
"GOOD", "GOOD", "GOOD", "GOOD"), VEGETATION = c("N", "Y", "N",
"Y", "N", "Y"), MUSSELS = c("N", "Y", "Y", "Y", "Y", "Y"), MUSSEL_ABUNDANCE = c("N",
"Y", "N", "N", "N", "Y"), DOM_SUBSTRATE = c("S", "S", "S", "H",
"S", "H"), HUMAN_FEATURES = c("N", "N", "N", "N", "N", "N"),
FISH = c("N", "N", "N", "N", "N", "Y"), GOBIES = c("N", "N",
"N", "N", "N", "Y"), OTHER_FISH = c("N", "N", "N", "N", "N",
"N"), NOTES2 = c("Interesting holes in the sediment", "Hard to see with plume of sediment",
"", "Tiny clump of what looks like mussels, could be rocks? Need second opinion",
"", "4-5 gobies"), COCR_COMMENTS = c(NA, NA, NA, NA, NA,
NA)), row.names = c(NA, 6L), class = "data.frame")
Thanks so much!