1

I am searching for particular words within a text vector using grepl. My function ran very well but with several TRUEs and FALSEs in the output. I am looking for a way to sum the number of the FALSEs and TRUEs in my output.

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
dasur schn
  • 61
  • 4
  • 1
    Use `table` to do this – akrun May 01 '19 at 21:19
  • 3
    @dasurschn You should format your question like [this](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) next time. – NelsonGon May 01 '19 at 21:21
  • 1
    as soon as you can (I think there's a minimum time of something like an hour for new users?), you can/are encouraged to post an answer based on @akrun's comment (unless they feel like doing it themselves in the meantime) – Ben Bolker May 01 '19 at 21:50

1 Answers1

2

Just to be clear on @akrun response,

text_vector <- c("hello world", "world map", "travels", "world", "hllo wrld")

res <- grepl(pattern = "world", text_vector)

> table(res)
FALSE  TRUE 
    2     3 

> sum(res) # no. TRUE
[1] 3

> sum(!res) # no. TRUE
[1] 2
Croote
  • 1,382
  • 1
  • 7
  • 15