[R] Extracting arithmetic mean for specific values from multiple .txt-files

Rui Barradas ruipbarradas at sapo.pt
Mon Jul 9 13:53:12 CEST 2012


Hello,

Your data example has dots in the column of interess. If those values 
are ntegers, this might do it.


fun <- function(x){
	dat <- read.table(x, skip=14)
	H <- as.numeric(gsub("\\.", "", dat[, 8]))
	mean(H)
}

sapply(list.files(pattern="XYZ.*\\.txt"), fun)

Now do what you want with the result, for instance, write.table().

Hope this helps.

Rui Barradas

Em 09-07-2012 12:20, vimmster escreveu:
> Dear Mr. Holtman,
>
> thank you for your reply.
>
> I think I did say which mean I needed: "all of these reaction times per test
> subject. ", which means that I need a file with the mean of reaction times
> of each file / of each test subject (because file XYZ_34.txt is identical
> with subject 34's data).
>
> There are 65 x 152 reaction times and I need 65 x mean(152 reaction times
> per test subject file) = 65 mean reaction times.
>
> I have now provided an example for a test subject 34:
>
> http://r.789695.n4.nabble.com/file/n4635834/XYZ_34.txt XYZ_34.txt
>
> Kind regards
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Extracting-arithmetic-mean-for-specific-values-from-multiple-txt-files-tp4635809p4635834.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list