Hello: Is there a way to get a mean from values stored in different rows? The data looks like this: YEAR-1, JAN, FEB, ..., DEC YEAR-2, JAN, FEB, ..., DEC YEAR-3, JAN, FEB, ..., DEC What I want is the mean(s) for just the consecutive winter months: YEAR-1.DEC, YEAR-2.JAN, YEAR-2.FEB YEAR-2.DEC, YEAR-3.JAN, YEAR-3.FEB etc. Thanks.
One way for doing it would be to combine the columns using paste and then use tapply to get the means. For example: set.seed(32341) a1 = sample(c("a","b"), 100,replace = T) a2 = sample(c("a","b"), 100,replace = T) y = rnorm(100) tapply(y,paste(a1,a2), mean) ----------------Contact Details:------------------------------------------------------- Contact me: Tal.Galili@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- On Thu, Oct 6, 2011 at 8:40 AM, SML <parallax@lafn.org> wrote:> Hello: > > Is there a way to get a mean from values stored in different rows? > > The data looks like this: > YEAR-1, JAN, FEB, ..., DEC > YEAR-2, JAN, FEB, ..., DEC > YEAR-3, JAN, FEB, ..., DEC > > What I want is the mean(s) for just the consecutive winter months: > YEAR-1.DEC, YEAR-2.JAN, YEAR-2.FEB > YEAR-2.DEC, YEAR-3.JAN, YEAR-3.FEB > etc. > > Thanks. > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]
Hello R people,>dim(exprs(estrogenrma)I have an expressionSet with 8 samples and 12695 features (genes)> estrogenrma$estrogenpresent present absent absent present present absent absent> estrogenrma$time.h10 10 10 10 48 48 48 48 present <- grep("present", as.character(estrogenrma$estrogen)) absent <- grep("absent", as.character(estrogenrma$estrogen)) ten <- grep("10", as.character(estrogenrma$time.h)) fortyeight <- grep("48", as.character(estrogenrma$time.h)) present.10 <- estrogenrma[, intersect(present, ten)] present.48 <- estrogenrma[, intersect(present, fortyeight)] absent.10 <- estrogenrma[, intersect(absent, ten)] absent.48 <- estrogenrma[, intersect(absent, fortyeight)] present.10, present.48, absent.10, and absent.48 are four expression sets with two samples and 12695 features. How can I make a new 2 new expressionsets, each have 12695 features and one sample where expressionset1 = (present.10 + present.48) / 2 expressionset2 = (absent.10 + absent.48) / 2 ? Thanks, Clayton ----- Original Message ----- From: "Tal Galili" <tal.galili at gmail.com> To: "SML" <parallax at lafn.org> Cc: r-help at r-project.org Sent: Thursday, October 6, 2011 4:09:43 AM Subject: Re: [R] Mean(s) from values in different row? One way for doing it would be to combine the columns using paste and then use tapply to get the means. For example: set.seed(32341) a1 = sample(c("a","b"), 100,replace = T) a2 = sample(c("a","b"), 100,replace = T) y = rnorm(100) tapply(y,paste(a1,a2), mean) ----------------Contact Details:------------------------------------------------------- Contact me: Tal.Galili at gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- On Thu, Oct 6, 2011 at 8:40 AM, SML <parallax at lafn.org> wrote:> Hello: > > Is there a way to get a mean from values stored in different rows? > > The data looks like this: > YEAR-1, JAN, FEB, ..., DEC > YEAR-2, JAN, FEB, ..., DEC > YEAR-3, JAN, FEB, ..., DEC > > What I want is the mean(s) for just the consecutive winter months: > YEAR-1.DEC, YEAR-2.JAN, YEAR-2.FEB > YEAR-2.DEC, YEAR-3.JAN, YEAR-3.FEB > etc. > > Thanks. > > ______________________________________________ > 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. >[[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.
Hi> > Hello: > > Is there a way to get a mean from values stored in different rows? > > The data looks like this: > YEAR-1, JAN, FEB, ..., DEC > YEAR-2, JAN, FEB, ..., DEC > YEAR-3, JAN, FEB, ..., DEC > > What I want is the mean(s) for just the consecutive winter months: > YEAR-1.DEC, YEAR-2.JAN, YEAR-2.FEB > YEAR-2.DEC, YEAR-3.JAN, YEAR-3.FEB > etc.Isn't colMean(yourdata) what you want? Regards Petr> > Thanks. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Note that exprs returns a matrix, so we can manipulate that just as we would for any other type of matrix. There is also a Bioconductor mailing list, which may be helpful. On Thu, Oct 6, 2011 at 4:56 AM, Clayton K Collings <ccolling at purdue.edu> wrote:> Hello R people, > >>dim(exprs(estrogenrma) > > I have an expressionSet with 8 samples and 12695 features (genes) > > >> estrogenrma$estrogen > ?present present absent absent present present absent absent >> estrogenrma$time.h > ?10 10 10 10 48 48 48 48 > > present <- grep("present", as.character(estrogenrma$estrogen)) > absent ?<- grep("absent", as.character(estrogenrma$estrogen)) > ten <- grep("10", as.character(estrogenrma$time.h)) > fortyeight ?<- grep("48", as.character(estrogenrma$time.h)) > > present.10 <- estrogenrma[, intersect(present, ten)] > present.48 <- estrogenrma[, intersect(present, fortyeight)] > absent.10 <- estrogenrma[, intersect(absent, ten)] > absent.48 <- estrogenrma[, intersect(absent, fortyeight)] > > > present.10, present.48, absent.10, and absent.48 are four expression sets > with two samples and 12695 features. > > How can I make a new 2 new expressionsets, each have 12695 features and one sample > where > expressionset1 = (present.10 + present.48) / 2 > expressionset2 = (absent.10 + absent.48) / 2 > ? > > Thanks, > Clayton > > ----- Original Message ----- > From: "Tal Galili" <tal.galili at gmail.com> > To: "SML" <parallax at lafn.org> > Cc: r-help at r-project.org > Sent: Thursday, October 6, 2011 4:09:43 AM > Subject: Re: [R] Mean(s) from values in different row? > > One way for doing it would be to combine the columns using paste and then > use tapply to get the means. > > For example: > > set.seed(32341) > a1 = sample(c("a","b"), 100,replace = T) > a2 = sample(c("a","b"), 100,replace = T) > y = rnorm(100) > tapply(y,paste(a1,a2), mean) > > > > ----------------Contact > Details:------------------------------------------------------- > Contact me: Tal.Galili at gmail.com | ?972-52-7275845 > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | > www.r-statistics.com (English) > ---------------------------------------------------------------------------------------------- > > > > > On Thu, Oct 6, 2011 at 8:40 AM, SML <parallax at lafn.org> wrote: > >> Hello: >> >> Is there a way to get a mean from values stored in different rows? >> >> The data looks like this: >> ?YEAR-1, JAN, FEB, ..., DEC >> ?YEAR-2, JAN, FEB, ..., DEC >> ?YEAR-3, JAN, FEB, ..., DEC >> >> What I want is the mean(s) for just the consecutive winter months: >> ?YEAR-1.DEC, YEAR-2.JAN, YEAR-2.FEB >> ?YEAR-2.DEC, YEAR-3.JAN, YEAR-3.FEB >> ?etc. >> >> Thanks. >> >> ______________________________________________ >> 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. >> > > ? ? ? ?[[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. > > ______________________________________________ > 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. >