[R] Average of data files in a directory

plpd00 plpd00 at gmail.com
Wed Jul 1 18:50:59 CEST 2009


Dear all,

I know it is as simple as c <- (a + b)/2 to compute the average
(element-wise) of two data vectors. However, I can't work out to compute the
average when you have many data vectors in a directory. I have done this:
------------------------------------
setwd("/.../data/")
listfiles <- list.files(pattern=".pre")    # list all datafiles in the
directory
loadfiles <- lapply(listfiles,read.csv)  # read the csv files
meanData <- lapply(loadfiles,mean) # intended to compute the element-wise
average. 
------------------------------------
Which does not produce the right result. Let me explain myself better... The
data files have the form (500 rows):
Time,Pressure
0,300
1,320
2,350
And I want to compute the average time (which is trivial since all time
vectors are the same) and the average pressure (from all the data files
collected). I know the function "mean" is not the one to use, but I cannot
find any function that allows me to compute average of two vectors. I hope
this is clear enough for you guys to understand. Thanks in advance for your
kind attention. 

Best regards,
Peter

-- 
View this message in context: http://www.nabble.com/Average-of-data-files-in-a-directory-tp24293290p24293290.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list