I have compiled a dataset of tweets using the Twitter API.
The dataset basically looks as follows:
Data <- data.frame(
X = c(1,2),
text = c("Hello @User1 #hashtag1, hello @User2 and @User3, #hashtag2", "Hello @User2 #hashtag3, hello @User1 and @User3, #hashtag4"),
screenname = c("author1", "author2")
)
Now I want to create a data.frame
for social network analysis. I want to show how each of the screennames (in the case of this example "author1" etc.) is linked to users ("@User1" etc.) and hashtags ("#hashtag1", etc.).
To so, I need to extract/copy users and hashtags from the "text" column and write them in new columns. The data.frame
should look like this:
Data <- data.frame(
X = c(1,2),
text = c("Hello @User1 #hashtag1, hello @User2 and @User3, #hashtag2", "Hello @User2 #hashtag3, hello @User1 and @User3, #hashtag4"),
screenname = c("author1", "author2"),
U1 = c("@User1", "@User2"),
U2 = c("@User2", "@User1"),
U3 = c("@User3", "@User3"),
U4 = c("",""),
U5 = c("",""),
H1 = c("#hashtag1", "#hashtag3"),
H2 = c("#hashtag2", "#hashtag4"),
H3 = c("",""),
H4 = c("",""),
H5 = c("","")
)
How can I extract/copy this information from the "text" column and write it into new columns?