[R] mean value calculation

arun smartpink111 at yahoo.com
Thu Oct 18 18:09:09 CEST 2012


Hi,

Are you looking for something like this?
#dat1 
aggregate(dat1[,2:4],by=list(dat1[,1]),FUN=mean)
#  Group.1 val1 val2. val3
#1     AKT  2.2  5.00    6
#2     CKT  4.5  5.75    7
A.K.




----- Original Message -----
From: Nico Met <nicomet80 at gmail.com>
To: R help <r-help at r-project.org>
Cc: 
Sent: Thursday, October 18, 2012 11:59 AM
Subject: [R] mean value calculation

Dear all,

I want to calculate mean values for multiple rows:

structure(list(Name = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L), .Label = c("AKT", "CKT"), class = "factor"), val1 = c(2,
3, 2, 2, 2, 5, 3, 8, 2), val2. = c(4, 5, 4, 8, 4, 8, 4, 7, 4),
    val3 = c(5, 6, 5, 9, 5, 9, 5, 9, 5)), .Names = c("Name",
"val1", "val2.", "val3"), class = "data.frame", row.names = c(NA,
9L))

For example: as an output I must get

Name val1 val2  val3  AKT   CKT

I wrote this :


#as.matrix(tapply(dat[,2:4], dat[,1], FUN = mean))

Error in as.matrix(tapply(met[, 2:4], met[, 1], FUN = mean)) :
  error in evaluating the argument 'x' in selecting a method for function
'as.matrix': Error in tapply(met[, 2:4], met[, 1], FUN = mean) :
  arguments must have same length

Thanks for you kind advise


Nico

    [[alternative HTML version deleted]]

______________________________________________
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