[rsplus] r ai
Viewer
- # install required packages
- install.packages(c("languageR", "tidyverse", "magrittr"))
- # load required packages
- library(languageR)
- library(tidyverse)
- library(magrittr)
- # randomly select 10 rows from danish
- danish %>%
- sample_n(10)
- # calculate number of different words in danish
- danish %>%
- distinct(word) %>%
- nrow()
- # calculate average response time for each affix
- danish %>%
- group_by(affix) %>%
- summarise(mean_rt = mean(logRT))
- # create linear plot showing relation between log word frequency and log RTs
- ggplot(data = danish, aes(x = logFreq, y = logRT)) +
- geom_smooth(method = "lm")
- # convert logRT to raw RTs
- danish %>%
- mutate(RT = exp(logRT))
- # compute average RTs by Sex
- danish %>%
- group_by(Sex) %>%
- summarise(mean_rt = mean(RT))
- # plot histogram of RTs by Sex
- ggplot(data = danish, aes(x = RT)) +
- geom_histogram(color = "black", fill = "white") +
- facet_wrap(~Sex)
- # create 'frequency' variable and compute average RTs by frequency
- danish %>%
- mutate(frequency = ifelse(logFreq > median(logFreq), "high freq", "low freq")) %>%
- group_by(frequency) %>%
- summarise(mean_rt = mean(RT))
- # plot histogram of RTs by frequency
- ggplot(data = danish, aes(x = RT)) +
- geom_histogram(color = "black", fill = "white") +
- facet_wrap(~frequency)
Editor
You can edit this paste and save as new: