I have the following problem. Suppose I save the data from an experiment in the following way. There are 21 pairs of std and cf. Each pairing is an experimental condition, and 4 data values are saved. The conditions are run (and data saved) in random order, though blocked such that all conditions are run once, then all in random order a second time, and so on (let's say 3 or 4 repetitions) What I want to do is to sum the data values of the repetitions. For example, suppose I have std cf hit miss fa cr 10 20 50 40 31 92 ... 10 20 40 35 42 87 ... 10 20 35 45 35 95 Then I want to sum the hit, miss, fa, and cr columns to get 10 20 125 120 108 274 totals for this condition. So I will do data<-read.table("data.dat",header=TRUE) But then how do I sum data$hit etc across the reps? If there is an alternative way to save the data to file(s) that makes this task easier that is fine. E.g. I could save each condition to its own file. But then I have to read in 21 files. Thanks very much for any help. Bill Simpson -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
You want to use aggregate(): data<-read.table("data.dat",header=TRUE) aggregate(data[,-(1:2)], by=list(std=data$std, cf=data$cf), sum) On 13-Oct-99 Bill Simpson wrote:> I have the following problem. > > Suppose I save the data from an experiment in the following way. There are > 21 pairs of std and cf. Each pairing is an experimental condition, and 4 > data values are saved. The conditions are run (and data saved) in random > order, though blocked such that all conditions are run once, then all in > random order a second time, and so on (let's say 3 or 4 repetitions) > > What I want to do is to sum the data values of the repetitions. For > example, suppose I have > std cf hit miss fa cr > 10 20 50 40 31 92 > ... > 10 20 40 35 42 87 > ... > 10 20 35 45 35 95 > > Then I want to sum the hit, miss, fa, and cr columns to get > 10 20 125 120 108 274 > totals for this condition. > > So I will do > data<-read.table("data.dat",header=TRUE) > But then how do I sum data$hit etc across the reps?-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Reasonably Related Threads
- read.table and factor
- Returning Data Frame from Function for use Outside Function
- Counting a number of "elements" in an object
- Is there a quick way to count the number of times each element in a vector appears?
- Non repetitive permutations/combinations of elements