'How to create a co-occurence matrix of words with txt in R

I have an unstructured text file with the topic of "anger". What I want to do is to create a co-occurence matrix/vector with "anger" as the column and all the other words in the text as rows. Something like the picture below. So I can further compute the cosine similarities between two words. I am new with R programming and your reply will be greatly appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source