-
Notifications
You must be signed in to change notification settings - Fork 56
/
hashtagExtractor.R
32 lines (27 loc) · 922 Bytes
/
hashtagExtractor.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#------------------------------------------------------
# Part of InstaCrawlR
# GitHub: https://github.com/JonasSchroeder/InstaCrawlR
# Code by Jonas Schröder
# See ReadME for instructions and examples
#------------------------------------------------------
library(stringr)
#Import Table and Extract Hashtags
text <- list()
htemp <- list()
htags <- data.frame()
data <- read.csv("table-HASHTAG-cleared.csv", sep = ";")
data <- as.matrix(data[-1])
maxrows <- nrow(data)
for(i in 1:maxrows){
text[i] <- as.character(data[i,5])
htemp <- str_extract_all(text[i], "#\\S+", TRUE)
if(ncol(htemp) != 0){
for(j in 1:ncol(htemp)){
htags[i,j] <- htemp[1,j]
}
}
}
#Save Hashtags as csv for Excel
write.csv(htags, "ht_unsort_HASHTAG.csv", fileEncoding = "UTF-8")
df_htags <- as.data.frame(table(unlist(htags)))
write.csv(df_htags, "ht_sort_HASHTAG.csv", fileEncoding = "UTF-8")