Created
April 5, 2018 17:20
-
-
Save mark-andrews/4458bc147c47ef54a04e03308e794eae to your computer and use it in GitHub Desktop.
How to do inner joins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(readr) | |
Df <- read_csv("data/AV_usereventsR_new.csv") | |
# create a table with correct responses | |
correct_responses <- with(Df, | |
tibble(stimulus = rep(key_config_1[1:8],2), | |
key_config = as.integer(c(rep(1,8), rep(2,8))), | |
correct_response = c(correct[1:8], correct.1[1:8]) | |
) | |
) | |
# Selected variables from the data. | |
# I selected the variables I guessed were important. | |
# Then inner join with correct_responses. | |
# Then see if response == correct_response. | |
Df_new <- Df %>% | |
mutate(stim_type = gsub(".*AV_", "", Stimulus), | |
stim_type = tolower(gsub("_.*", "", stim_type)), | |
response_num = as.integer(gsub("[A-Z]*", "", response)) | |
) %>% select(subject = Subject, | |
stimulus = stim_type, | |
key_config = Key_config, | |
response = response_num, | |
rt = `RT..ms.`) %>% | |
inner_join(correct_responses, | |
by = c('stimulus', 'key_config')) %>% | |
mutate(accuracy = response == correct_response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment