r - Word count for text in column -


i have dataset column containing text follows

    column1     ----------------------------------------------------------     dapagliflozin 10 mg / metformin hydrochloride      dapagliflozin 5 mg / metformin hydrochloride       fortamet            glucophage           glumetza           metformin hydrochloride           metformin hydrochloride  / pioglitazone 15 mg          metformin hydrochloride  / pioglitazone 30 mg       

i trying obtain word count every unique word, example, word count metformin, word count hydrochloride, etc. need help; tried table function, uses whole row 1 word , that's not helpful.

we can use combination of strsplit/unlist/table. split column strings strsplit specifying split space (\\s+). output list. use unlist change list vector , use table count.

 table(unlist(strsplit(yourdf$column1, '\\s+')) 

Comments