You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: episodes/frequency-analysis.Rmd
+22-10Lines changed: 22 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -126,28 +126,40 @@ articles_filtered |>
126
126
127
127
```
128
128
129
-
<!-- The analyses just made can easily be adjusted. For instance, if we want look at the words by `pillar_name` instead of by `president`, we simply replace `president` with `pillar_name` in the code.
129
+
<!-- The analyses just made can easily be adjusted. For instance, if we want look at the words by `pillar_name` instead of by `president`, we simply replace `president` with `pillar_name` in the code.-->
130
130
131
-
```{r vis_per_pillar}
132
-
articles_filtered |>
131
+
<!--```{r vis_per_pillar}-->
132
+
<!--articles_filtered |>
133
133
count(date, word, sort = TRUE) |>
134
134
group_by(date) |>
135
135
slice(1:10) |>
136
136
ggplot(mapping = aes(x = n, y = word, colour = date, shape = date)) +
137
-
geom_point()
138
-
``` -->
137
+
geom_point() -->
138
+
<!-- ``` -->
139
+
140
+
141
+
Interesting that numbers occurs in the Sports section. Lets have a look at where it occurs. In order to do so we have to go back to our original object `articles` where we have the full text of articles. It would be nice to see the context in wich for instance 1 occurs.
139
142
140
-
Interesting that numbers occurs in the Sports section. Lets have a look at where it occurs. In order to do so we have to go back to our original object `articles` where we have the full text of articles.
143
+
In order to do this we need to use a `package` named `quanteda`, so lets install the package, and load it in to memory.
141
144
145
+
```{r, eval = FALSE}
146
+
install.packages("quanteda")
147
+
library(quanteda)
148
+
```
149
+
150
+
In order to get the context we will use the function `kwic`
142
151
```{r}
143
152
articles |>
144
153
filter(section == "Sport") |>
145
-
filter(str_detect(text, "\\b1\\b")) |>
146
-
select(text) |>
147
-
head()
154
+
# filter(str_detect(text, "\\b1\\b")) |>
155
+
# slice(1) |>
156
+
pull(text) |>
157
+
tokens() |>
158
+
kwic(pattern = "1", window = 10)
159
+
148
160
```
149
161
150
-
<!-- SNAK MED CHRISTIAN ANG at få ordet i kontekst, så 10 ord før og 10 ord efter -->
162
+
So what we are doing is looking for at keyword in context, and that is exactly what the function `kwic` does. It locates the string we write in the argument `pattern` and takes the amout of words before and after the keyword given in the argument `window`.
When performing text analysis in R, the built-in functions in R are not sufficient. It is therefore necessary to install some additional packages. In this course we will be using the packages `tidyverse` and `tidytext`.
0 commit comments