data <- read.csv(here::here("data", "raw", "participant001.csv"))
str(data)
## 2. Inspect the data ---------------------------------------------------------
## Check its structure and look at the first few rows.
## Make any corrections to the data types needed.
str(data)
summary(data)
data$correct <- as.logical(data$correct)
## 3. Filter the data ----------------------------------------------------------
## Keep only trials with rt between 250 and 900 ms and
## keep only correct trials.
valid_data <- data[
data$correct == TRUE &
data$rt >= 250 &
data$rt <= 900,
]
## 4. Summarize by condition ---------------------------------------------------
## Using tapply(), compute the mean RT for high_load
## vs low_load using the filtered data.
## Be sure to handle missing values.
tapply(valid_data$rt, valid_data$condition, na.rm = TRUE)
## 4. Summarize by condition ---------------------------------------------------
## Using tapply(), compute the mean RT for high_load
## vs low_load using the filtered data.
## Be sure to handle missing values.
tapply(valid_data$rt, valid_data$condition, mean, na.rm = TRUE)
print(paste(
"You have", nrow(valid_data),
"total valid trials and",
sum(valid_data$rt < 500, na.rm = TRUE),
"fast trials."
))
## 8. Bonus: Print a summary message -------------------------------------------
## Use paste() or paste0() to print a short message:
## "You have X total valid trials and Y fast trials."
print(paste0(
"You have", nrow(valid_data),
"total valid trials and",
sum(valid_data$rt < 500, na.rm = TRUE),
"fast trials."
))
## 8. Bonus: Print a summary message -------------------------------------------
## Use paste() or paste0() to print a short message:
## "You have X total valid trials and Y fast trials."
print(paste(
"You have", nrow(valid_data),
"total valid trials and",
sum(valid_data$rt < 500, na.rm = TRUE),
"fast trials."
))
## 1. Import the data ----------------------------------------------------------
## Read in your assigned participant CSV file.
## (The data located in here::here("data/raw"))
read.csv(here::here("data/raw/participant001.csv"))
## 1. Import the data ----------------------------------------------------------
## Read in your assigned participant CSV file.
## (The data located in here::here("data/raw"))
participant_data <- read.csv(here::here("data/raw/participant001.csv"))
## 1. Import the data ----------------------------------------------------------
## Read in your assigned participant CSV file.
## (The data located in here::here("data/raw"))
df <- read.csv(here::here("data/raw/participant001.csv"))
## 2. Inspect the data ---------------------------------------------------------
## Check its structure and look at the first few rows.
## Make any corrections to the data types needed.
str(df)
head(df)
## 3. Filter the data ----------------------------------------------------------
## Keep only trials with rt between 250 and 900 ms and
## keep only correct trials.
valid_data <- data[
data$correct == TRUE &
data$rt >= 250 &
data$rt <= 900,
]
data
## 1. Import the data ----------------------------------------------------------
## Read in your assigned participant CSV file.
## (The data located in here::here("data/raw"))
data <- read.csv(here::here("data/raw/participant001.csv"))
## 1. Import the data ----------------------------------------------------------
## Read in your assigned participant CSV file.
## (The data located in here::here("data/raw"))
data <- read.csv(here::here("data/raw/participant001.csv"))
## 2. Inspect the data ---------------------------------------------------------
## Check its structure and look at the first few rows.
## Make any corrections to the data types needed.
str(data)
head(data)
## 3. Filter the data ----------------------------------------------------------
## Keep only trials with rt between 250 and 900 ms and
## keep only correct trials.
valid_data <- data[
data$correct == TRUE &
data$rt >= 250 &
data$rt <= 900,
]
tapply(valid_data$rt, valid_data$condition, mean, na.rm = TRUE)
View(valid_data)
## 3. Filter the data ----------------------------------------------------------
## Keep only trials with rt between 250 and 900 ms and
## keep only correct trials.
valid_data <- data[
data$correct == TRUE &
data$rt >= 250 &
data$rt <= 900,
]
high_load <- valid_data[valid_data$condition == "high_load", ]
high_load_mean <- mean(high_load$rt, na.rm = TRUE)
low_load <- valid_data[valid_data$condition == "low_load", ]
low_load_mean <- mean(low_load$rt, na.rm = TRUE)
tapply(valid_data$rt, valid_data$condition, mean, na.rm = TRUE)
## 1. Import the data ----------------------------------------------------------
## Read in your assigned participant CSV file.
## (The data located in here::here("data/raw"))
data <- read.csv(here::here("data/raw/participant001.csv"))
data$correct <- as.logical(data$correct)
## 3. Filter the data ----------------------------------------------------------
## Keep only trials with rt between 250 and 900 ms and
## keep only correct trials.
valid_data <- data[
data$correct == TRUE &
data$rt >= 250 &
data$rt <= 900,
]
tapply(valid_data$rt, valid_data$condition, mean, na.rm = TRUE)
?tapply
## 5. Write a small function ---------------------------------------------------
## Define a function called classify_rt() that takes a
## single RT value and returns:
## "fast"   if rt < 500
## "slow"   if rt >= 500
## "missing" if rt is NA
classify_rt <- function(rt) {
if(is.na(rt)) {
return("missing")
} else if(rt < 500) {
return("fast")
} else {
return("slow")
}
}
classify_rt(400)
classify_rt(NA)
classify_rt(900)
data$rt_class <- classify_rt(data$rt)
## 5. Write a small function ---------------------------------------------------
## Define a function called classify_rt() that takes a
## single RT value and returns:
## "fast"   if rt < 500
## "slow"   if rt >= 500
## "missing" if rt is NA
classify_rt <- function(rt) {
if (is.na(rt)) {
return("missing")
} else if (rt < 500) {
return("fast")
} else {
return("slow")
}
}
## Vector version:
classify_rt <- function(rt_value) {
ifelse(
is.na(rt_value), "missing",
ifelse(rt_value < 500, "fast", "slow")
)
}
## 6. Apply your function ------------------------------------------------------
## Create a new column in the *original* data frame
## called rt_class, using either a for loop or ifelse()
## to apply your classify_rt() logic to each trial.
data$rt_class <- classify_rt(data$rt)
View(data)
## 5. Write a small function ---------------------------------------------------
## Define a function called classify_rt() that takes a
## single RT value and returns:
## "fast"   if rt < 500
## "slow"   if rt >= 500
## "missing" if rt is NA
classify_rt <- function(rt) {
if (is.na(rt)) {
return("missing")
} else if (rt < 500) {
return("fast")
} else {
return("slow")
}
}
## For loop:
data$rt_class <- NA # create an empty column
for (i in 1:nrow(data)) {
data$rt_class[i] <- classify_rt(data$rt[i])
}
_
## Vector version:
classify_rt <- function(rt_value) {
ifelse(
is.na(rt_value), "missing",
ifelse(rt_value < 500, "fast", "slow")
)
}
for (i in 1:nrow(data)) {
data$rt_class[i] <- classify_rt(data$rt[i])
}
## 1. Import the data ----------------------------------------------------------
## Read in your assigned participant CSV file.
## (The data located in here::here("data/raw"))
data <- read.csv(here::here("data/raw/participant001.csv"))
data$correct <- as.logical(data$correct)
## 3. Filter the data ----------------------------------------------------------
## Keep only trials with rt between 250 and 900 ms and
## keep only correct trials.
valid_data <- data[
data$correct == TRUE &
data$rt >= 250 &
data$rt <= 900,
]
## 4. Summarize by condition ---------------------------------------------------
## Using tapply(), compute the mean RT for high_load
## vs low_load using the filtered data.
## Be sure to handle missing values.
tapply(valid_data$rt, valid_data$condition, mean, na.rm = TRUE)
## 4. Summarize by condition ---------------------------------------------------
## Using tapply(), compute the mean RT for high_load
## vs low_load using the filtered data.
## Be sure to handle missing values.
means <- tapply(valid_data$rt, valid_data$condition, mean, na.rm = TRUE)
## Vector version:
classify_rt <- function(rt_value) {
ifelse(
is.na(rt_value), "missing",
ifelse(rt_value < 500, "fast", "slow")
)
}
data$rt_class <- NA # create an empty column
for (i in 1:nrow(data)) {
data$rt_class[i] <- classify_rt(data$rt[i])
}
View(data)
str(data)
head(data)
## 1. Import the data ----------------------------------------------------------
## Read in your assigned participant CSV file.
## (The data located in here::here("data/raw"))
data <- read.csv(here::here("data/raw/participant001.csv"))
## 2. Inspect the data ---------------------------------------------------------
## Check its structure and look at the first few rows.
## Make any corrections to the data types needed.
str(data)
## 1. Import the data ----------------------------------------------------------
## Read in your assigned participant CSV file.
## (The data located in here::here("data/raw"))
read.csv(here::here('data/raw/participant001.csv'))
## 1. Import the data ----------------------------------------------------------
## Read in your assigned participant CSV file.
## (The data located in here::here("data/raw"))
data <- read.csv(here::here("data/raw/participant001.csv"))
## 2. Inspect the data ---------------------------------------------------------
## Check its structure and look at the first few rows.
## Make any corrections to the data types needed.
str(data)
head(data)
data$correct <- as.logical(data$correct)
View(data)
## 2. Inspect the data ---------------------------------------------------------
## Check its structure and look at the first few rows.
## Make any corrections to the data types needed.
str(data)
## 3. Filter the data ----------------------------------------------------------
## Keep only trials with rt between 250 and 900 ms and
## keep only correct trials.
valid_data <- data[rt > 250 & rt < 250 & correct == TRUE]
## 3. Filter the data ----------------------------------------------------------
## Keep only trials with rt between 250 and 900 ms and
## keep only correct trials.
valid_data <- data[data$rt > 250 & data$rt < 250 & data$correct == TRUE]
## 3. Filter the data ----------------------------------------------------------
## Keep only trials with rt between 250 and 900 ms and
## keep only correct trials.
valid_data <- data[data$rt > 250 & data$rt < 250 & data$correct == TRUE, ]
## 3. Filter the data ----------------------------------------------------------
## Keep only trials with rt between 250 and 900 ms and
## keep only correct trials.
valid_data <- data[data$rt > 250 & data$rt < 900 & data$correct == TRUE, ]
## 4. Summarize by condition ---------------------------------------------------
## Using tapply(), compute the mean RT for high_load
## vs low_load using the filtered data.
## Be sure to handle missing values.
tapply(data, data$condition, mean, na.rm = TRUE)
## 4. Summarize by condition ---------------------------------------------------
## Using tapply(), compute the mean RT for high_load
## vs low_load using the filtered data.
## Be sure to handle missing values.
tapply(valid_data, valid_data$condition, mean, na.rm = TRUE)
tapply(valid_data$rt, valid_data$condition, mean, na.rm = TRUE)
## 1. Import the data ----------------------------------------------------------
## Read in your assigned participant CSV file.
## (The data located in here::here("data/raw"))
data <- here::here("data", "raw", "participant001.csv")
## 2. Inspect the data ---------------------------------------------------------
## Check its structure and look at the first few rows.
## Make any corrections to the data types needed.
str(data)
## 2. Inspect the data ---------------------------------------------------------
## Check its structure and look at the first few rows.
## Make any corrections to the data types needed.
str(data)
## Make any corrections to the data types needed.
str(data)
## 2. Inspect the data ---------------------------------------------------------
## Check its structure and look at the first few rows.
## Make any corrections to the data types needed.
str(data)
## 1. Import the data ----------------------------------------------------------
## Read in your assigned participant CSV file.
## (The data located in here::here("data/raw"))
data <- here::here("data", "raw", "participant001.csv")
data <- here::here("data/raw/participant001.csv")
## 1. Import the data ----------------------------------------------------------
## Read in your assigned participant CSV file.
## (The data located in here::here("data/raw"))
data <- read.csv(here::here("data", "raw", "participant001.csv"))
## 2. Inspect the data ---------------------------------------------------------
## Check its structure and look at the first few rows.
## Make any corrections to the data types needed.
str(data)
## 5. Summarize by condition ---------------------------------------------------
## Using tapply(), compute the mean RT for high_load
## vs low_load using the filtered data.
## Be sure to handle missing values.
tapply(valid_data$rt, valid_data$condition, mean, na.rm = TRUE)
data <- read.csv(here::here("data/raw/participant001.csv"))
## 2. Inspect the data ---------------------------------------------------------
## Check its structure and look at the first few rows.
## Make any corrections to the data types needed.
str(data)
