Hello, R experts: I got data like this: group duplicate treatment A Y 5 A Y 3 A N 6 B Y 2 B N 4 B Y 1 How to sort the data and calculate the average treatment value for each group in two level of duplicate. Results like this: group duplicate treatment A Y 4 A N 6 B Y 1.5 B N 4 Thank you in advance. Josh
Have you considered "aggregate"? hope this helps. spencer graves szhan at uoguelph.ca wrote:>Hello, R experts: >I got data like this: >group duplicate treatment >A Y 5 >A Y 3 >A N 6 >B Y 2 >B N 4 >B Y 1 >How to sort the data and calculate the average treatment value for each group >in two level of duplicate. Results like this: >group duplicate treatment >A Y 4 >A N 6 >B Y 1.5 >B N 4 >Thank you in advance. > >Josh > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help > >
On Wed, 2003-10-01 at 20:15, szhan at uoguelph.ca wrote:> Hello, R experts: > I got data like this: > group duplicate treatment > A Y 5 > A Y 3 > A N 6 > B Y 2 > B N 4 > B Y 1 > How to sort the data and calculate the average treatment value for each group > in two level of duplicate. Results like this: > group duplicate treatment > A Y 4 > A N 6 > B Y 1.5 > B N 4 > Thank you in advance. > > Josh# Create a dataframe df <- data.frame(group = c(rep("A", 3), rep("B", 3)), duplicate = c("Y", "Y", "N", "Y", "N", "Y"), treatment = c(5, 3, 6, 2, 4, 1)) # Use aggregate aggregate(df$treatment, list(df$group, df$duplicate), mean) Group.1 Group.2 x 1 A N 6.0 2 B N 4.0 3 A Y 4.0 4 B Y 1.5 Aggregate returns a data frame in this case, so that you can then set the colnames and order the output if you wish. HTH, Marc Schwartz
An alternative to renaming columns in the ouput of aggregate is to provide names in the "by" list as follows: aggregate(df$treatment, list(gp=df$group, dup=df$duplicate), mean) hope this helps. spencer graves Marc Schwartz wrote:>On Wed, 2003-10-01 at 20:15, szhan at uoguelph.ca wrote: > > >>Hello, R experts: >>I got data like this: >>group duplicate treatment >>A Y 5 >>A Y 3 >>A N 6 >>B Y 2 >>B N 4 >>B Y 1 >>How to sort the data and calculate the average treatment value for each group >>in two level of duplicate. Results like this: >>group duplicate treatment >>A Y 4 >>A N 6 >>B Y 1.5 >>B N 4 >>Thank you in advance. >> >>Josh >> >> > > ># Create a dataframe >df <- data.frame(group = c(rep("A", 3), rep("B", 3)), > duplicate = c("Y", "Y", "N", "Y", "N", "Y"), > treatment = c(5, 3, 6, 2, 4, 1)) > ># Use aggregate >aggregate(df$treatment, list(df$group, df$duplicate), mean) > Group.1 Group.2 x >1 A N 6.0 >2 B N 4.0 >3 A Y 4.0 >4 B Y 1.5 > >Aggregate returns a data frame in this case, so that you can then set >the colnames and order the output if you wish. > >HTH, > >Marc Schwartz > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help > >
A little more succinctly and I hope also helpful:> with(df, aggregate(list(mean=treatment),list(group = group, duplicate = duplicate), mean)) Note that the name of the summary of treatment is likely best to be different from the name of the treatment variable itself. It is tempting to do something fancy picking up the name of the called function automatically, but I mostly use an unnamed summary function (x) { ...}, so I won't bother. (BTW did I ever mention here how much I prefer with() to attach()/forget.to.detach() ?)> From: Marc Schwartz [mailto:MSchwartz at medanalytics.com] > Sent: 02 October 2003 15:37> attach(df) > aggregate(as.data.frame(treatment), > list(group = group, duplicate = duplicate), mean) > ### Remember to 'detach(df)'. > > Doing it this way, 'treatment' retains the name attribute > when passed to aggregate, rather than as a vector.Simon Fear Senior Statistician Syne qua non Ltd Tel: +44 (0) 1379 644449 Fax: +44 (0) 1379 644445 email: Simon.Fear at synequanon.com web: http://www.synequanon.com Number of attachments included with this message: 0 This message (and any associated files) is confidential and\...{{dropped}}
Hello All: Is there such a function in the R libraries: exact logistic regression? Thanks, ANDREW
No, as far as I know. However the brlr package performs bias-reduced logistic regression that might be useful for you. (for instance yields ML estimates when there is separation in data and even CMLE do not exist) See the reference in the help file ?brlr, best, vito ----- Original Message ----- From: Andrew Criswell <arc at arcriswell.com> To: <R-help at stat.math.ethz.ch> Sent: Thursday, October 09, 2003 5:36 AM Subject: [R] Exact logistic regression models> Hello All: > > Is there such a function in the R libraries: exact logistic regression? > > Thanks, > ANDREW > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help