user3456230 user3456230 - 2 months ago 5
R Question

remove all words that start with "@" from a string

how can I remove all words that start with "@" from a string?

For example,
"@AgnezMo On @AirAsia Airbus A320-216 Fleet with @NinetologyMY Livery -- 9M-AHG cc: @AgnesMonicaEnt @agnezone http://t.co/hfXwUQq2Oq"

I would like to have the string to be
"On Airbus A320-216 Fleet with Livery -- 9M-AHG cc: http://t.co/hfXwUQq2Oq"

Answer

Try this where s is the input:

gsub("@\\w+ *", "", s)

giving:

"On Airbus A320-216 Fleet with Livery -- 9M-AHG cc: http://t.co/hfXwUQq2Oq"
Comments