check capital words in text and extract it
gsub, r
Solution
Another option is
library(stringr)
sapply(str_extract_all(Text, '\\b[A-Z]+\\b'), paste, collapse=' ')
# [1] "I JAY" "I AM NOT HAPPY" "YOU ARE IRRITATING"
#[4] "" ""
Or
gsub("[a-z][A-Za-z]+|[A-Za-z][a-z]+", '', Text)
#[1] "I JAY" "I AM NOT HAPPY" "YOU ARE IRRITATING"
#[4] " " ""
data
Text<-c('I am JAY','I AM NOT HAPPY','YOU ARE IRRITATING','so Funny','hEY')
Problem
I want to extract all capital words from the text. Lets say my data is like--> ``` Text<-c('I am JAY','I AM NOT HAPPY','YOU ARE IRRITATING','so Funny','hEY) ``` So output should be like --> ``` > output ``` [1] "I JAY" "I AM NOT HAPPY" "YOU ARE IRRITATING" "" "" Please help me for this.