Mega‐Grant EEG Preprocessing Outcome Excel - LeoLedesma237/LeoWebsite GitHub Wiki
library(readxl)
library(tidyverse)
library(openxlsx)
library(psych)
# Set working directory
setwd("Y:/STUDY 1/All EEG Files Organized/Preprocessed_RAW/CSV_preprocessing")
# List in all the files that are Closed and Open (Respectively)
All.Closed <- list.files(pattern = "Closed")
All.Open <- list.files(pattern = "Open")
# Open each file by condition and save them respectively
All.Open.list <- list()
All.Closed.list <- list()
for(ii in 1:length(All.Closed)) {
All.Closed.list[ii](/LeoLedesma237/LeoWebsite/wiki/ii) <- read.csv(All.Closed[ii])
All.Open.list[ii](/LeoLedesma237/LeoWebsite/wiki/ii) <- read.csv(All.Open[ii](/LeoLedesma237/LeoWebsite/wiki/ii))
}
# Save all as a data frame
All.Closed.df <- tibble(do.call(rbind, All.Closed.list))
All.Open.df <- tibble(do.call(rbind, All.Open.list))
# Create a variable that mentions the % of remaining data
All.Closed.df <- mutate(All.Closed.df, PercentRemaining = round(RemainingSec/StartingSec,2)*100)
All.Open.df <- mutate(All.Open.df, PercentRemaining = round(RemainingSec/StartingSec,2)*100)
# Get some descriptives of the % of remaining data
describe(All.Closed.df$PercentRemaining)
describe(All.Open.df$PercentRemaining)
hist(All.Closed.df$PercentRemaining)
hist(All.Open.df$PercentRemaining)
# Load in all component rejection components
setwd("Y:/STUDY 1/All EEG Files Organized/Preprocessed_RAW/CSV_components rejected")
All.Closed.Comp <- list.files(pattern = "Closed")
All.Open.Comp <- list.files(pattern = "Open")
# Open each file by condition and save them respectively
All.Open.Comp.list <- list()
All.Closed.Comp.list <- list()
for(ii in 1:length(All.Closed.Comp)) {
All.Closed.Comp.list[ii](/LeoLedesma237/LeoWebsite/wiki/ii) <- read.csv(All.Closed.Comp[ii])
All.Open.Comp.list[ii](/LeoLedesma237/LeoWebsite/wiki/ii) <- read.csv(All.Open.Comp[ii](/LeoLedesma237/LeoWebsite/wiki/ii))
}
# Save all as a data frame
All.Closed.Comp.df <- tibble(do.call(rbind, All.Closed.Comp.list))
All.Open.Comp.df <- tibble(do.call(rbind, All.Open.Comp.list))
# Join the datasets
Closed.df <- left_join(All.Closed.df, All.Closed.Comp.df, by = "FileName")
Open.df <- left_join(All.Open.df, All.Open.Comp.df, by = "FileName")
# Save the names of the files that have at least 80 % of the data remaining
Closed.df2 <- filter(Closed.df, PercentRemaining >= 80)
Open.df2 <- filter(Open.df, PercentRemaining >= 80)
# Set a save directory
setwd("Y:/STUDY 1/All EEG Files Organized/Preprocessed_RAW")
write.xlsx(list(Cleaned.Closed = Closed.df2,
Cleaned.Open = Open.df2),
file = "EEG Raw File Names3 (ready for FFT).xlsx")