vimmster
2012-Jul-08 23:01 UTC
[R] Extracting arithmetic mean for specific values from multiple .txt-files
Hello, I'm coming straight to the point: I have 65 .txt-Files named "XYZ_1.txt" to "XYZ_65.txt" (each number represents a test subject). I have to open them in Microsoft Excel to see the exact structure. In each of those .txt-files there are reaction time values (in milliseconds) from line 15, column H to line 166, column H for each test subject (and a couple of other data in the other colums of course). My problem is, that I only need the arithmetic mean for all of these reaction times per test subject. --> Again: I have 65 test subjects and according to Excel 152 reaction times for each test subject / in each .txt-file. Is there an easy way to only extract the arithmetic mean for each test subject in an Excel file column? Thanks for your answers! -- View this message in context: http://r.789695.n4.nabble.com/Extracting-arithmetic-mean-for-specific-values-from-multiple-txt-files-tp4635809.html Sent from the R help mailing list archive at Nabble.com.
jim holtman
2012-Jul-08 23:35 UTC
[R] Extracting arithmetic mean for specific values from multiple .txt-files
Since you did not provide an example of the file, I will take a guess at the content and show to to extract the values and take the mean of all of them since you did not say if you want the mean of each file, or a single means. myData <- do.call(c, lapply(1:65, function(.file){ x <- read.csv(paste0("XYZ_", .file, ".txt")) x[15:166, 'colH'] }))) mean(myData) On Sun, Jul 8, 2012 at 7:01 PM, vimmster <superdodge at gmx.net> wrote:> Hello, > > I'm coming straight to the point: > > I have 65 .txt-Files named "XYZ_1.txt" to "XYZ_65.txt" (each number > represents a test subject). > > I have to open them in Microsoft Excel to see the exact structure. > > In each of those .txt-files there are reaction time values (in milliseconds) > from line 15, column H to line 166, column H for each test subject (and a > couple of other data in the other colums of course). > > My problem is, that I only need the arithmetic mean for all of these > reaction times per test subject. > > --> Again: I have 65 test subjects and according to Excel 152 reaction times > for each test subject / in each .txt-file. > > Is there an easy way to only extract the arithmetic mean for each test > subject in an Excel file column? > > Thanks for your answers! > > -- > View this message in context: http://r.789695.n4.nabble.com/Extracting-arithmetic-mean-for-specific-values-from-multiple-txt-files-tp4635809.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.-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it.
jim holtman
2012-Jul-09 18:36 UTC
[R] Extracting arithmetic mean for specific values from multiple .txt-files
I think the real problem is the first data line: 2 1 1 3 27 0 6 1.200.995 Notice the two periods in the value. The previous solution was getting rid of all the periods. If you leave out this value, you get 339.5. if you change it to 1200.995, you get 345.21, so you data is incorrect. On Mon, Jul 9, 2012 at 9:54 AM, vimmster <superdodge at gmx.net> wrote:> Dear Mr. Barradas, > > your solution comes very close to what I want. > > But I have two questions left: > > > First question: If "R" computes the mean for the reaction times of test > subject 34 (the example I provided above), it says "310112.0", but if I use > the "mean"-function in Excel it says "345.210". Apart from the dots in the > column of interest (which you mentioned before), the mean is obviously not > the same. Do you have any idea why? > > Second question: Why are the dots in the column of interest problematic? > > Kind regards > > -- > View this message in context: http://r.789695.n4.nabble.com/Extracting-arithmetic-mean-for-specific-values-from-multiple-txt-files-tp4635809p4635854.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.-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it.