Quantcast
Channel: Active questions tagged row - Stack Overflow
Viewing all articles
Browse latest Browse all 471

How to filter rows that have certain strings in R [closed]

$
0
0

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! :)


Viewing all articles
Browse latest Browse all 471

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>