The mean function works in data.frames:

lapply(loadfiles, mean)
[[1]]
    Time Pressure
  1.0000 323.3333

[[2]]
    Time Pressure
  1.0000 323.3333


On Wed, Jul 1, 2009 at 1:50 PM, plpd00 <plpd00@gmail.com> wrote:

>
> 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.
>
> ______________________________________________
> R-help@r-project.org mailing list
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]


