I am searching for particular words within a text vector using grepl
. My function ran very well but with several TRUE
s and FALSE
s in the output. I am looking for a way to sum the number of the FALSE
s and TRUE
s in my output.
Asked
Active
Viewed 204 times
1

NelsonGon
- 13,015
- 7
- 27
- 57

dasur schn
- 61
- 4
-
1Use `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
-
1as 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 Answers
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