[R] Calculating Mean

arun smartpink111 at yahoo.com
Mon Jun 3 13:24:45 CEST 2013


HI,You could also try:

set.seed(24)
dat1<- data.frame(Reaction_time=sample(24:60,80,replace=TRUE),Categ=rep(1:8,each=10))
with(dat1,tapply(Reaction_time,list(Categ),FUN=mean))
#   1    2    3    4    5    6    7    8 
#43.7 39.8 37.5 42.7 33.9 42.3 43.2 40.0 
#or
library(plyr)
 ddply(dat1,.(Categ),summarize, RTMean=mean(Reaction_time))
#  Categ RTMean
#1     1   43.7
#2     2   39.8
#3     3   37.5
#4     4   42.7
#5     5   33.9
#6     6   42.3
#7     7   43.2
#8     8   40.0
A.K.

----- Original Message -----
From: Laura Thomas <skagandbonegirl at hotmail.com>
To: r-help at r-project.org
Cc: 
Sent: Monday, June 3, 2013 5:15 AM
Subject: [R] Calculating Mean

Hi All,

Sorry about this quite basic, but I am very new to R.

I have a data file which has a dependent variable (reaction time) and a couple of independent variables, one of which is coded 1-8; I want to calculate the reaction time for each of the 8 codes of the independent variable.

Thanks for any help,

Laura

______________________________________________
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