[R] sum elements of dataframe
Martyn Plummer
plummer at iarc.fr
Wed Oct 13 16:48:29 CEST 1999
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list