Hi I am quite new to R programming. What I want to do is to replicate a series of actions to multiple files. My first step is to create a function that reads a file, and then performs subsequent actions. For example
analyze <- function(filename){data<- read.csv(filename, header=TRUE)
average<- mean(data[,2])
print (average)}
analyze ("my first file")
However, I am having a problem with the code, because it does not give the right result. data is not updated when I change the filename. I don't know what went wrong. Can anyone give me a simpler alternative solution? Many thanks.