Hi,
I am a beginner of R and I have a basic problem.
I am using RStudio to read a series of .xls files. The organisation in columns is identical for all files. I am trying to split the file into trials, and I can't figure out how to do it for all trials in once.
Below my code
# 1. Read Data Viewer sample report - which must contain the
# following variables in order:
# RECORDING_SESSION_LABEL,TRIAL_INDEX,TIMESTAMP,LEFT_GAZE_X,
# LEFT_GAZE_Y,RIGHT_GAZE_X,RIGHT_GAZE_Y,RESOLUTION_X,RESOLUTION_Y
# Split report into trials
#---------------------------
#code the .xls files to be read
pre1 <- "Sample_Report_V0100"
pre2 <- str_pad(1:99, pad = 0,width = 2 , "left")
pre3 <- 1
suf <- ".xls"
file.names <- paste(pre1, sep = "", paste(pre2,pre3,suf, sep =""))
rm(pre1, pre2, pre3, suf)
file.names
allfiles <- list.files (path = "C:/Users/Daniela Canu/Documents/R/MS_Toolbox_Daniela/MS_Toolbox_Daniela/data", pattern = "*.xls", full.names=TRUE)
allfiles
df.list <- lapply(allfiles, read.table)
df.list
all_data <- sum(complete.cases(file.names))
dt <- split(all_data,all_data[,2])
the error i get is the following Error in all_data[, 2] : incorrect number of dimensions
I see this error not existing if I read one file alldata <- read.table(all_data, na.strings=c("."), header = TRUE)
How to split all files into trials?
Thanks a lot!