Hello, I want to subset specific rows of data from 80 .csv files and write those subsets into new .csv files. The data I want to subset starts on a different row for each original .csv file. I've created variables that identify which row the subset should start and end on, but I want to loop through this process and I am not sure what to do. I've attempted to write the loop below, albeit, much of it is pseudo code. If anyone can provide me with some tips I'd appreciate it.
#### This data file is used to create the variables where the subsetting starts and ends for each participant #### mig.data <- read.csv("/Users/cdanyluck/Documents/Studies/MIG - Dissertation/Data & Syntax/mig.data.csv") # These are the variable names for the start and end of each subset of relevant data (baseline, audio, and free) participant.ids <- mig.processed.data$participant.id participant.baseline.start <- mig.processed.data$baseline.row.start participant.baseline.end <- mig.processed.data$baseline.row.end participant.audio.start <- mig.processed.data$audio.meditation.row.start participant.audio.end <- mig.processed.data$audio.meditation.row.end participant.free.start <- mig.processed.data$free.meditation.row.start participant.free.end <- mig.processed.data$free.meditation.row.end # read into a list the individual files from which to subset the data participant.files <- list.files("/Users/cdanyluck/Documents/Studies/MIG - Dissertation/Data & Syntax/MIG_RAW DATA & TXT Files/Plain Text Files") # loop through each participant for (i in 1:length(participant.files)) { # get baseline rows results.baseline <- participant.files[participant.baseline.start[i]:participant.baseline.end[i],] # get audio rows results.audio <- participant.files[participant.audio.start[i]:participant.audio.end[i],] # get free rows results.free <- participant.files[participant.free.start[i]:participant.free.end[i],] # write out participant relevant data write.csv(results.baseline, file="baseline[i].csv") write.csv(results.audio, file = "audio[i].csv") write.csv(results.free, file = "free[i].csv") } -- Chad M. Danyluck, MA PhD Candidate, Psychology University of Toronto “There is nothing either good or bad but thinking makes it so.” - William Shakespeare [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.