I'm trying to use an if else statement and the filter function to clean some data and get rid of values that are too high.
This is an example of my tibble:
animals.data <- c("pig",99,"dog",30,"pig",20,"pig",200,"dog",120,"dog",40)
animals <- matrix(animals.data, nrow=6,ncol=2, byrow=TRUE)
colnames(animals) <- c("Variable","Value")
This is the code I'm trying to run:
animals <- animals %>%
filter(
if (animals$Variable=="pig") {
animals$Value < 100
} else {
animals$Value < 140
}
)
This is the error I keep getting:
the condition has length > 1 and only the first element will be used
I'm wanting to iterate through both columns in the tibble. Thank you in advance! I also welcome if you also have any comments about bad practice things I'm doing, I'm a beginner.