install.packages("DescTools")
library(DescTools)
LCM(c(4,5))
LCM(c(4,5, 6))
LCM(1/c(8.3, 9.1))
LCM(c(8, 9))
LCM(c(8, 9, 7))
LCM(83, 91)
LCM(83, 91)/83
LCM(83, 91)/91
LCM(83, 91, 115)
LCM(83, 91, 115)/115
1/seq(8, 12, .1)
data.table(hz = seq(8, 12, .1), per = 1/seq(8, 12, .1))
library(data.table)
data.table(hz = seq(8, 12, .1), per = 1/seq(8, 12, .1))
data.table(hz = seq(8, 12, .01), per = 1/seq(8, 9, .01))
data.table(hz = seq(8, 9, .05), per = 1/seq(8, 9, .05))
data.table(hz = seq(10, 12, .05), per = 1/seq(10, 12, .05))
1/c(8.3, 10.8)
LCM(930, 1204)
LCM(930, 1204)/4
LCM(930, 1203)
LCM(930, 1204)/4
LCM(930, 1203)/4
LCM(931, 1203)/4
strsplit("askdj 10 23", " ")
strsplit("askdj 10 23", " ")[[1]]
library(data.table)
a <- data.frame(a = c("qrad wert wet", "sef aef wetr"))
a
d <- data.table(a)
a <- data.frame(var = c("qrad wert wet", "sef aef wetr"))
d <- data.table(a)
a
b
a
d
d <- data.table(a, n = strplit(var, " ")[[1]][2])
d <- data.table(a, n = strplt(var, " ")[[1]][2])
d <- data.table(a, n = strsplit(var, " ")[[1]][2])
d <- data.table(a, n = strsplit(a$var, " ")[[1]][2])
d
setwd("/Volumes/GoogleDrive-103405781638992341338/My Drive/projecten_cloud/whatsapp_text_miner")
library(ggplot2); theme_set(theme_classic())
library(data.table)
library(progress)
library(lubridate)
library(stringr)
parseLines <- function(S){
lines <- readLines(S)
l <- 1
d <- NULL
curmsg <- NULL
pb <- progress_bar$new(total = length(lines))
for(i in 1:(length(lines)-1)){
pb$tick()
stop <- ifelse(substr(lines[l+1], 1, 1) == "[", TRUE, FALSE)
start <- ifelse(substr(lines[l], 1, 1) == "[", TRUE, FALSE)
if(start){
curmsg <- lines[l]
}
if(stop){
d <- c(d, curmsg)
} else {
curmsg <- paste(curmsg, lines[l+1], sep = "\n")
}
l <- l + 1
}
d <- data.table(raw = d,
date = dmy_hms(substr(d, 2, 21), tz="Europe/London"),
source = S,
content = substr(d, 24, length(d))
)
d[, type := ifelse(str_detect(content, ":"), "msg", "status_change")]
return(d)
}
d <- rbind(parseLines("tafelgasten.txt"),
parseLines("spuut.txt"))
setkey(d, date)
save(d, file = "chattable.rdata")
d
d[, sender := ifelse(type == "msg", str_split(content, ":")[[1]][1], str_split(content, " ")[[1]][1]), by = 1:nrow(d)]
d[, sender := as.factor(sender)]
unique(d$sender)
setwd("/Volumes/GoogleDrive/Shared drives/ExpMeP/2021/rug_dcac/assignments/assignment4")
# Reading in our favorite two packages
library(data.table)
library(ggplot2)
# Packages needed for statistical analyses
library(afex)
library(emmeans)
load("demo_exp_dat_2021.rdata")
# Inspect the information in the data frame
colnames("dat")
dat[, .N, by = pp]
dif_lvl <- unique(dat$difficulty)
phase_names <- unique(dat$phase)
trial_nrs <-unique(dat$trial)
# Rename column name
setnames(dat, "response_time_keyboard_response", "RT")
# Number of trials for each participant per experimental phase
dat[time == 0, .N, by = .(pp, practice, difficulty)]
#EXPLANATION
# 1) dat[, .N, by = pp] lists the nr of observations per participant. problem: every 10 ms counts as an 'observation', and there is a ton of 10 ms within one trial
# 2) time == 0 to prevent it from counting every trial as an observation multiple times (for every 'time' within a trial)
# 3) count observations for trials where time == 0; list by pp, list by practice and list by difficulty
# Average number of trials per experimental phase
mean_trial <- dat[time == 0, .N, by = .(pp, practice)]
mean_trial[, .(N_Mean=mean(N)), by = .(practice)]
#EXPLANATION
#make a variable out of N (nr of trials per pp per exp phase); and then calculate the mean of that variable
#(N_Mean=mean(N) is just renaming the outcome of the calulation mean(N)
# Remove practice trials from data table
dat <- dat[ !(practice == 'yes')]
# Average pupil dilation over time for subject 1
avg_pupil1 <- dat[pp == 1, .(pupil_meanpp1 = mean(pupil)), by = .(time, difficulty)]
# And visualise
plotdat <- dat[pp == 1, .(pupil_mean = mean(pupil)), by = time]
ggplot(plotdat, aes(x = time, y = pupil_mean)) +
geom_line()
a = rnorm(100)
a
mad(a)
a %between% c(1, 2)
library(data.table)
a %between% c(1, 2)
d <- data.table(r = 1, names = c("Rinze", "Rinze", "Rinze", "Lyke", "Michiel", "Michiel", "Nienke", "Michiel", "Lyke", "Rinze"))
library(data.table)
d <- data.table(r = 1, names = c("Rinze", "Rinze", "Rinze", "Lyke", "Michiel", "Michiel", "Nienke", "Michiel", "Lyke", "Rinze"))
d
library(data.table)
d <- rbind(
data.table(r = 1, names = c("Rinze", "Rinze", "Rinze", "Lyke", "Michiel", "Michiel", "Nienke", "Michiel", "Lyke", "Rinze")),
data.table(r = 2, names = c("Nienke", "Rinze", "Rinze", "Michiel", "Michiel", "Lyke", "Karlien", "Lyke", "Freya")),
data.table(r = 3, names = c("Lyke", "Rinze", "Rinze", "Jikke", "Michiel", "Freya", "Freya")),
data.table(r = 4, names = c("Rinze", "Jikke", "Rinze", "Michiel", "Lyke", "Jikke")),
data.table(r = 6, names = c("Michiel", "Michiel", "Lyke")),
data.table(r = 1, names = c("Michiel", "Michiel"))
)
d
counts <- d[, .N, by = r]
counts
counts <- d[, .N, by = .(r, names)]
counts
library(ggplot2)
ggplot(counts, aes(x = r, y = N, color = names)) +
geom_line()
ggplot(counts, aes(x = r, y = N, color = names)) +
geom_line() +
geom_point()
counts
all <- c("Michiel", "Rob", "Iris", "Kris", "Jikke", "Nienke", "Karlien", "Freya", "Lyke", "Rinze", "Scholte")
setwd("~/Documents/projecten_local/10K Faces/face-processor")
library(data.table)
d <- fread("subject-0.csv")
d <- fread("subject-1.csv")
d[, mean(correct)]
d[, mean(correct), by = target]
d[, mean(correct), by = target_sex]
d[, mean(correct), by = .(target, target_sex)]
