I am trying to create an hashtag extraction function in R. This function will extract a hashtags from a post, if there are any, else will give a blank. My function is like <
Thanks everyone for all the help, I got it worked somehow, thought it is almost similar as Shalini's answer 1.replacing all NAs on message
message[is.na(message)]='abc'
2.function for extracting the Hashtags
hashtag_extrac= function(text){
match = str_extract_all(text,"#\\S+")
if (match!= "") {
match
} else {
'' }}
hashtags= sapply(message, hashtag_extrac)