Hashtag Extract function in R Programming

前端 未结 3 2013
悲哀的现实
悲哀的现实 2020-12-12 08:18

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 <

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-12 08:29

    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 {
    '' }}
    

    applying function on whole column

    hashtags= sapply(message, hashtag_extrac)
    

提交回复
热议问题