Good morning, I would like to know if is possible somebody can help me with this please: I would like to calculate the median of grouped data, this is an example: ID PM adt_01 25.255 adt_01 225.36 adt_01 14.2325 adt_02 15 adt_02 12.3 adt_03 15.2 adt_03 148.3 adt_03 25.5 adt_03 14.25 I need the median of adt_01, 02 and 03 , I know that I have to split first my data and then ask for the median but the code I have is not working. Thank you very much if you can help me with the code maria
Tena koe Maria ?tapply Specifically: tapply(yourData$PM, yourData$ID, median) HTH .... Peter Alspach> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of "Mar?a del > Pilar M?rquez" > Sent: Thursday, 28 January 2010 7:06 a.m. > To: r-help at r-project.org > Subject: [R] median of grouped data > > Good morning, > I would like to know if is possible somebody can help me with > this please: > I would like to calculate the median of grouped data, this is > an example: > > ID PM > adt_01 25.255 > adt_01 225.36 > adt_01 14.2325 > adt_02 15 > adt_02 12.3 > adt_03 15.2 > adt_03 148.3 > adt_03 25.5 > adt_03 14.25 > > I need the median of adt_01, 02 and 03 , I know that I have > to split first my data and then ask for the median but the > code I have is not working. > > Thank you very much if you can help me with the code maria > > ______________________________________________ > 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. >
Like this? d = read.table(textConnection("ID PM adt_01 25.255 adt_01 225.36 adt_01 14.2325 adt_02 15 adt_02 12.3 adt_03 15.2 adt_03 148.3 adt_03 25.5 adt_03 14.25"),head=T) d d$PM <- as.numeric(d$PM) ddply(d,.(ID),numcolwise(median)) Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish & Wildlife Service California, USA --- On Wed, 1/27/10, "Mar?a del Pilar M?rquez" <marquezvilla at wisc.edu> wrote:> From: "Mar?a del Pilar M?rquez" <marquezvilla at wisc.edu> > Subject: [R] median of grouped data > To: r-help at r-project.org > Date: Wednesday, January 27, 2010, 10:05 AM > Good morning, > I would like to know if is possible somebody can help me > with this please: > I would like to calculate the median of grouped data, this > is an example: > > ID? ? PM > adt_01? 25.255 > adt_01? 225.36 > adt_01? 14.2325 > adt_02? 15 > adt_02? 12.3 > adt_03? 15.2 > adt_03? 148.3 > adt_03? 25.5 > adt_03? 14.25 > > I need the median of adt_01, 02 and 03 , I know that I have > to split first my data and then ask for the median but the > code I have is not working. > > Thank you very much if you can help me with the code > maria > > ______________________________________________ > 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. >
Check the package doBy as well (pretty handy for analysis of grouped data). library(doBy) summaryBy(PM~ID,data=d,FUN=median) HTH, -Girish -- View this message in context: http://n4.nabble.com/median-of-grouped-data-tp1311971p1312386.html Sent from the R help mailing list archive at Nabble.com.