Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Removing rows that have slashes in a specific column

In a data frame, I have some strings in a column that have /// in it. Is there a way for me to search for strings that have that /// pattern and remove that row completely?

I have this DF1:

Name Key group1 group2 group3
XAS /// HUA test1234 10 10 8
MPA1 /// AAS2 test4553 8 7 4
MPAS test3341 5 5 5
SSPA1 test2142 5 6 8
MAS61A test4722 6 7 4

Essentially, this dataframe is very large, and so I want to keyword search in the first column for that pattern, and if it is present, to drop that row. To get this as the result below. Whats the best way to do so? Thanks!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Name Key group1 group2 group3
MPAS test3341 5 5 5
SSPA1 test2142 5 6 8
MAS61A test4722 6 7 4
# DF1
Name <- c("XAS /// HUA", "MPA1 /// AAS2", "MPAS", "SSPA1", "MAS61A")
Key <- c("test1234", "test4553", "test3341", "test2142", "test4722")
group1 <- c(10, 8, 5, 5, 6)
group2 <- c(10, 7, 5, 6, 7)
group3 <- c(8, 4, 5, 8, 4)
DF1 <- data.frame(Name, Key, group1, group2, group3)

>Solution :

Using negated grepl.

DF1[!grepl('/', DF1$Name), ]
#     Name      Key group1 group2 group3
# 3   MPAS test3341      5      5      5
# 4  SSPA1 test2142      5      6      8
# 5 MAS61A test4722      6      7      4
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading