I have a dataframe (let's call it df) such as:
Animal reg1 RHO2 FRC3 AKL4 PdL5 JYT6 AUV7 BRET8 RHO9 AUV10 DDR11 FRC12 FRC13 PdL14 UOQ
And I want to filter the rows by the column "reg", which contains only the following strings: FRC, RHO, AUV, BRET and PdL. So, the output should be something like this:
Animal reg1 RHO2 FRC4 PdL6 AUV7 BRET8 RHO9 AUV11 FRC12 FRC13 PdL
I tried using dplyr
functions such as grepl
and filter,
but every time there was a error message saying that this functions don't work for logical sentences. Since I'm still learning to use R, I'm not very familiar with the arguments and what they mean. Here are some examples of what I tried to do:
filter(df$reg, !grepl('RHO|FRC|AUV|BRET|PdL'))-> df1
df[grep("FRC"|"RHO"|"AUV"|"BRET"|"PdL", df$reg), , drop = FALSE] -> df1
What can I do? Thank you! :)