wmedian <- function(directory, day) {
files_list <- list.files(directory, full.names = TRUE)
dat <- data.frame()
for (i in 1:5) {
dat <- rbind(dat, read.csv(files_list[i]))
}
dat_subset <- dat[which(dat[, "Day"] == day), ]
median(dat_subset[, "Weight"], na.rm = TRUE)
}
The above code is returning the following error in R when I try to define it ""rror: unexpected input in "wmedian <- function(directory, day) {". I'm actually learning R right now and this code was straight from a tutorial. I tried re-writing the code, and also copy/pasting the code. Both are returning errors and I can't figure out why. What are your thoughts?
The goal of this function is to bind a set of csv files together, that have columns "Weight" and "Day". The function binds those files together and return the median of Weight for a given Day.