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

2012-07-12 Thread vimmster
Dear Mr. Holtman and especially dear Rui, thank you VERY much. You helped me a lot! I've just added the following: rsort <- ratios[order(ratios$vpNum),] Now the test subjects are arranged according to their vpNum. Thanks a lot again! -- View this message in context: http://r.789695.n4.nabb

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

2012-07-11 Thread vimmster
Dear Rui, thank you VERY much. You helped me a lot! I've just added the following: rsort <- ratios[order(ratios$vpNum),] Now the test subjects are arranged according to their vpNum. Thanks a lot again! -- View this message in context: http://r.789695.n4.nabble.com/Extracting-arithmetic-mean

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

2012-07-11 Thread Rui Barradas
Hello, Try make.row <- function(x, skip = 14, column){ dat <- read.table(x, skip = skip - 1, header = TRUE, stringsAsFactors = FALSE) vpNum <- dat$vpNum[1] trial <- length(dat[[ column ]]) correct <- sum(dat$correct == 1) result <- c(vpNum, trial, correct, correct/trial)

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

2012-07-10 Thread vimmster
Dear Rui, 1) With test subject I mean each file (I have posted three similar files above (2, 50 and 1112), but each test subject has one exact file (which differs of course! --> 2, 50 an 1112 are the same file but I renamed it for the problem described ans solved above). In this file the vpNum is

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

2012-07-10 Thread vimmster
Dear Rui, 1) With test subject I mean each file (I have posted three similar files above (2, 50 and 1112), but each test subject has one exact file (which differs of course! --> 2, 50 an 1112 are the same file but I renamed it for the problem described ans solved above). In this file the vpNum is

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

2012-07-10 Thread Rui Barradas
Hello, I'm glad it help. As for this second question, you should explain yourself better. 1. What is a test subject, which column records its id? vpNum? 2. You say "divided per trials or trialCount". Does this mean per trial number (example: divide by 1, by 2, by 3, etc, by 149) or per number

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

2012-07-10 Thread vimmster
Dear Rui, thank you very much. Your solution works perfectly. One last question: I need to write a function, with ONE value (here: a ratio) for the correct reactions divided per trials or trialCount, respectively, FOR EACH test subject. "/" means "divided by" in the following. I need the rati

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

2012-07-10 Thread Rui Barradas
Hello, Ok, I think that there were two problems. One, gsub substitutes all (g - global) occurrences of the search pattern, so both periods were removed. The other, it would allways consider column 8 as character, but when there are no values with two periods it's read in with class numeric. Bo

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

2012-07-10 Thread vimmster
Dear Mr. Holtman, but I cannot leave out the value and cannot change the values to 1200.995 manually (for each test subject with a reaction time > 1000 ms), because the first your lead to incomplete data and the latter would be too time-consuming. Dear Rui, here I have three files, which have ex

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

2012-07-09 Thread jim holtman
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 34

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

2012-07-09 Thread Rui Barradas
Hello, There must be a difference in the file you are processing and in the one excel and I are: > fun <- function(x){ + dat <- read.table(x, skip=14) + dat[ , 8] <- as.numeric(gsub("\\.", "", dat[, 8])) + mean(dat[, 8]) + } > > sapply(list.files(pattern="XYZ.*\\.txt"), fun) XYZ_34.txt 3452

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

2012-07-09 Thread vimmster
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". Ap

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

2012-07-09 Thread Rui Barradas
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 wh

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

2012-07-09 Thread vimmster
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). T

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

2012-07-08 Thread jim holtman
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.c

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

2012-07-08 Thread vimmster
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,