Remove rows containing only one word of a column?

Hi.

I'm trying to write a code that removes all rows that only contain one word in them. E.g., if the object has 2 words, it should stay.

So in my data, I would like to remove row 1 and 5 since they have one word of column "Matchid".

data.frame(
stringsAsFactors = FALSE,
Sampleid = c("AVM_360","AVM_360","AVM_360",
"AVM_360","AVM_360","AVM_360","AVM_360","AVM_360",
"AVM_360"),
Currentid = c("Bibasis vasutana",
"Bibasis vasutana","Bibasis vasutana","Bibasis vasutana",
"Bibasis vasutana","Bibasis vasutana","Bibasis vasutana",
"Bibasis vasutana","Bibasis vasutana"),
Matchp = c("100.0","100.0","100.0",
"100.0","100.0","100.0","100.0","100.0","100.0"),
Matchid = c("Bibasis","Bibasis vasutana",
"Bibasis vasutana","Bibasis vasutana","Bibasis",
"Bibasis vasutana","Bibasis vasutana","Bibasis vasutana",
"Bibasis nikos")
)

thank you!!

Hi @niko_bio
One way to do it is to filter for rows that have one or more white space.

sample_data <- data.frame(
  stringsAsFactors = FALSE,
  Sampleid = c("AVM_360","AVM_360","AVM_360",
               "AVM_360","AVM_360","AVM_360","AVM_360","AVM_360",
               "AVM_360"),
  Currentid = c("Bibasis vasutana",
                "Bibasis vasutana","Bibasis vasutana","Bibasis vasutana",
                "Bibasis vasutana","Bibasis vasutana","Bibasis vasutana",
                "Bibasis vasutana","Bibasis vasutana"),
  Matchp = c("100.0","100.0","100.0",
             "100.0","100.0","100.0","100.0","100.0","100.0"),
  Matchid = c("Bibasis","Bibasis vasutana",
              "Bibasis vasutana","Bibasis vasutana","Bibasis",
              "Bibasis vasutana","Bibasis vasutana","Bibasis vasutana",
              "Bibasis nikos")
)
library(tidyverse)

sample_data %>% filter(str_detect(str_trim(Matchid), "\\s+"))

Perfect, thank you very much.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.