[R] "Simplifying" matrices ?
arun
smartpink111 at yahoo.com
Thu Dec 6 18:21:15 CET 2012
Hi,
It is better to provide an example dataset.
Try this:
# example on data.frame
dat1<-data.frame(year=rep(c(1998,1999,2000),each=3),event=rep(LETTERS[1:3],times=3),team=rep(1:3,each=3),total=rep(c(300,320,140),each=3))
library(plyr)
res<-ddply(dat1,.(year,team),function(x) colMeans(x[4]))
res
# year team total
#1 1998 1 300
#2 1999 2 320
#3 2000 3 140
with(dat1,aggregate(total,by=list(year=year,team=team),mean))
# year team x
#1 1998 1 300
#2 1999 2 320
#3 2000 3 140
A.K.
----- Original Message -----
From: rajashekar <rajashekarpanneti at yahoo.in>
To: r-help at r-project.org
Cc:
Sent: Thursday, December 6, 2012 8:45 AM
Subject: [R] "Simplifying" matrices ?
Hi again,
the previous answers were great. I was able to do what was planned.
Now, I would like to do the following to a matrix:
|| year | event | team | total ||
where I can have multiple "event" per "team", but each "team" only has
a "year" and a "total". Thus, this table has multiple lines for the
same "team" where only the "event" changes.
Considering this, how can I output this:
|| year | team | total ||
where each "team" occurs only once, and the "event" was discarded.
Hope I made myself clear.
Thanks in advance.
-----
--
View this message in context: http://r.789695.n4.nabble.com/Simplifying-matrices-tp4652329.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
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