Re: [R] by group

2021-11-02 Thread PIKAL Petr
-Original Message- > From: R-help On Behalf Of Val > Sent: Monday, November 1, 2021 10:08 PM > To: r-help@R-project.org (r-help@r-project.org) > Subject: [R] by group > > Hi All, > > How can I generate mean by group. The sample data looks like as follow, > dat

Re: [R] by group

2021-11-01 Thread Val
Thank you all for your help! On Mon, Nov 1, 2021 at 8:47 PM Bert Gunter wrote: > > ... maybe not. According to Rdocumentation.org: > > reshape2's status is: > > reshape2 is retired: only changes necessary to keep it on CRAN will be > made. We recommend using tidyr in

Re: [R] by group

2021-11-01 Thread Bert Gunter
... maybe not. According to Rdocumentation.org: reshape2's status is: reshape2 is retired: only changes necessary to keep it on CRAN will be made. We recommend using tidyr instead. Bert Gunter "The trouble with having an open mind is that people keep coming along

Re: [R] by group

2021-11-01 Thread Avi Gross via R-help
ables: $ F: num 12 13.3 12 $ M: num 15 16.3 15 From: Bert Gunter Sent: Monday, November 1, 2021 8:50 PM To: Val Cc: Avi Gross ; r-help mailing list Subject: Re: [R] by group "A decent example was given and I see Andrew provided a base R reply that should be sufficient.

Re: [R] by group

2021-11-01 Thread Rasmus Liland
Dear Val, also consider using reshape2::dcast dat <- structure(list(Year = c(2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2003L, 2003L, 2003L, 2003L, 2003L, 2003L), Sex = c("M", "M", "M", "F", "F", "F", "M", "M

Re: [R] by group

2021-11-01 Thread Bert Gunter
; > matter of programming taste and convenience and so on. > > > > Maybe Val can share more about the situation so we can see what is > helpful > > and what is not. Realistically, I can think of way too many ways to get > the > > required output. > > > > -

Re: [R] by group

2021-11-01 Thread Avi Gross via R-help
vot_wider(names_from = Sex, values_from = M) %>% as.data.frame %>% round(1) -Original Message- From: Val Sent: Monday, November 1, 2021 8:15 PM To: Avi Gross Cc: r-help mailing list Subject: Re: [R] by group Thank you Avi, One question, I am getting this error from thi

Re: [R] by group

2021-11-01 Thread Val
ng taste and convenience and so > > on. > > > > Maybe Val can share more about the situation so we can see what is > > helpful and what is not. Realistically, I can think of way too many > > ways to get the required output. > > > > -Original Message- > &g

Re: [R] by group

2021-11-01 Thread Avi Gross via R-help
later. Good luck. -Original Message- From: Val Sent: Monday, November 1, 2021 7:44 PM To: Avi Gross Cc: r-help mailing list Subject: Re: [R] by group Thank you all! I can assure you that this is not HW. This is a sample of my large data set and I want a simple and efficient approach

Re: [R] by group

2021-11-01 Thread Val
R-help On Behalf Of Jim Lemon > Sent: Monday, November 1, 2021 6:25 PM > To: Val ; r-help mailing list > Subject: Re: [R] by group > > Hi Val, > I think you answered your own question: > > by(dat$wt,dat[,c("Sex","Year")],mean) > > Jim > > On

Re: [R] by group

2021-11-01 Thread Avi Gross via R-help
ee what is helpful and what is not. Realistically, I can think of way too many ways to get the required output. -Original Message- From: R-help On Behalf Of Jim Lemon Sent: Monday, November 1, 2021 6:25 PM To: Val ; r-help mailing list Subject: Re: [R] by group Hi Val, I think you answere

Re: [R] by group

2021-11-01 Thread Avi Gross via R-help
t versions that have added a somewhat different way to do pipelines. -Original Message- From: R-help On Behalf Of Val Sent: Monday, November 1, 2021 5:08 PM To: r-help@R-project.org (r-help@r-project.org) Subject: [R] by group Hi All, How can I generate mean by group. The sample da

Re: [R] by group

2021-11-01 Thread Jim Lemon
Hi Val, I think you answered your own question: by(dat$wt,dat[,c("Sex","Year")],mean) Jim On Tue, Nov 2, 2021 at 8:09 AM Val wrote: > > Hi All, > > How can I generate mean by group. The sample data looks like as follow, > dat<-read.table(text="Year Sex wt > 2001 M 15 > 2001 M 14 > 2001 M 16 > 2

Re: [R] by group

2021-11-01 Thread Andrew Simmons
I would usually use 'tapply'. It splits an object into groups, performs some function on each group, and then (optionally) converts the input to something simpler. For example: tapply(dat$wt, dat$Year, mean) # mean by Year tapply(dat$wt, dat$Sex , mean) # mean by Sex tapply(dat$wt, list(dat$Yea

[R] by group

2021-11-01 Thread Val
Hi All, How can I generate mean by group. The sample data looks like as follow, dat<-read.table(text="Year Sex wt 2001 M 15 2001 M 14 2001 M 16 2001 F 12 2001 F 11 2001 F 13 2002 M 14 2002 M 18 2002 M 17 2002 F 11 2002 F 15 2002 F 14 2003 M 18 2003 M 13 2003 M 14 2003 F 15 2003 F 10 2003 F 11 ",h

Re: [R] by group

2015-10-20 Thread Val
un...@r-project.org] On Behalf Of Val > Sent: Tuesday, 13 October 2015 4:06 AM > To: r-help@r-project.org > Subject: [R] by group > > Hi all, > > > Assume that I have the following data set : > > cntry state city Gender (1=F and 2=M) > > 1 1 1 1 > 1 1 1 2 >

Re: [R] by group

2015-10-12 Thread MCGUIRE, Rhydwyn
www.health.nsw.gov.au -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Val Sent: Tuesday, 13 October 2015 4:06 AM To: r-help@r-project.org Subject: [R] by group Hi all, Assume that I have the following data set : cntry state city Gender (1=F and 2=M) 1 1 1 1 1

[R] by group

2015-10-12 Thread Val
Hi all, Assume that I have the following data set : cntry state city Gender (1=F and 2=M) 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 2 1 2 2 2 1 2 3 2 1 2 3 1 I want to calculate the number of Females and Males, total (F+M) and percentage (F/M) by country, state and city. Here is t

Re: [R] BY GROUP in evir R package

2011-07-07 Thread Pfaff, Bernhard Dr.
> > > > - Original Message > From: "Pfaff, Bernhard Dr." > To: Peter Maclean ; Dr. Bernhard Pfaff > > Cc: "r-help@r-project.org" > Sent: Wed, July 6, 2011 8:17:12 AM > Subject: AW: [R] BY GROUP in evir R package > > Hello Pet

Re: [R] BY GROUP in evir R package

2011-07-06 Thread Peter Maclean
Dr. Pfaff: After using str; can you give an example on data extration (e.g. for $par.ests and @residuals) - Original Message From: "Pfaff, Bernhard Dr." To: Peter Maclean ; Dr. Bernhard Pfaff Cc: "r-help@r-project.org" Sent: Wed, July 6, 2011 8:17:12 AM Subje

Re: [R] BY GROUP in evir R package

2011-07-06 Thread Pfaff, Bernhard Dr.
che Nachricht- > Von: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] Im Auftrag von Peter Maclean > Gesendet: Mittwoch, 6. Juli 2011 09:25 > An: Dr. Bernhard Pfaff > Cc: r-help@r-project.org > Betreff: Re: [R] BY GROUP in evir R package > > Dr. P

Re: [R] BY GROUP in evir R package

2011-07-06 Thread Peter Maclean
Dr. Pfaff: How do we pass the "by" results to "rlevel.gev" function to get the return level and also save the results (both rg2(par.ests and $par.ses) and rl) as.data.frame? #Grouped vector Gdata <- data.frame(n = rep(c(1,2,3), each = 100), y = rnorm(300)) library(evir) require(plyr) #Model f

Re: [R] BY GROUP IN GEV

2011-06-29 Thread Peter Maclean
Dennis: It walks for small datset.  Peter Maclean Department of Economics UDSM - Original Message From: Dennis Murphy To: Peter Maclean Cc: r-help@r-project.org Sent: Mon, June 27, 2011 8:37:00 PM Subject: Re: [R] BY GROUP IN GEV HI: Since you didn't provide a reprodu

Re: [R] BY GROUP IN GEV

2011-06-27 Thread Dennis Murphy
g message: > In sqrt(diag(varcov)) : NaNs produced > >  Peter Maclean > Department of Economics > UDSM > > > > - Original Message > From: Dennis Murphy > To: Peter Maclean > Sent: Wed, June 22, 2011 11:37:02 PM > Subject: Re: [R] BY GROUP IN

Re: [R] BY GROUP IN GEV

2011-06-27 Thread Peter Maclean
To: Peter Maclean Sent: Wed, June 22, 2011 11:37:02 PM Subject: Re: [R] BY GROUP IN GEV Hi: I think you need CP  <- lapply(MAS, function(x){gev(x$CP1, 100, method = "BFGS", control =                     list(maxit = 500))}) See if that works out. HTH, Dennis On Wed, Jun 22, 20

Re: [R] BY GROUP IN GEV

2011-06-22 Thread Peter Maclean
I am trying to run gev (general extreme value) function in “evir” package. My data is divided by state. I am using the following codes but it is not working. I will appreciate any help.   #Split data MAS <- split(MA, MA$states)   CP  <- lapply(MAS, function(x){gev(MAS$CP1, 100, method = "BFGS", c

Re: [R] by group testing

2010-08-04 Thread Joshua Wiley
On Wed, Aug 4, 2010 at 10:17 AM, Joshua Wiley wrote: > Hello, > > This will put the results of the Fisher test in a list, with each > element of the list being the results for mouse type a, b, c, and d. > > mice <- rep(letters[1:4],10) > outcome <- sample(c(0,1),length(mice),replace=T) > group <-

Re: [R] by group testing

2010-08-04 Thread Joshua Wiley
Hello, This will put the results of the Fisher test in a list, with each element of the list being the results for mouse type a, b, c, and d. mice <- rep(letters[1:4],10) outcome <- sample(c(0,1),length(mice),replace=T) group <- c(rep("A",length(mice)/2),rep("B",length(mice)/2)) my.data <- data.

[R] by group testing

2010-08-04 Thread cheba meier
Hello, I have a data set which is similar to the following data mice <- rep(letters[1:4],10) outcome <- sample(c(0,1),length(mice),replace=T) group <- c(rep("A",length(mice)/2),rep("B",length(mice)/2)) my.data <- data.frame(mice,outcome,group) my.sort.data <- my.data[order(my.data[,1]),] I woul

Re: [R] by-group processing

2009-05-08 Thread hadley wickham
On Wed, May 6, 2009 at 8:12 PM, jim holtman wrote: > Ths should do it: > >> do.call(rbind, lapply(split(x, x$ID), tail, 1)) >         ID Type N > 45900 45900    I 7 > 46550 46550    I 7 > 49270 49270    E 3 Or with plyr: library(plyr) ddply(x, "id", tail, 1) plyr encapsulates the common split-

Re: [R] by-group processing

2009-05-08 Thread Jun Shen
This is a problem much like the one I had a few weeks ago. David's solution is more concise. Try xtfrm() or rank() for factor sorting d=data[order(data$ID,-xtfrm(data$Type)),] should work. By the way I got it from Duncan. Jun On Fri, May 8, 2009 at 4:09 PM, David Freedman <3.14da...@gmail.com> w

Re: [R] by-group processing

2009-05-08 Thread David Freedman
sorry about the mistake - the -data$Type doesn't work: the '-' sign isn't valid for factors. I *thought* I had checked this before submitting a response ! HufferD wrote: > > On Thursday, May 07, 2009 7:45 PM, David Freedman wrote: > > > ...how about: > > d=data[order(data$ID,-data$Type),]

Re: [R] by-group processing

2009-05-08 Thread David Huffer
On Thursday, May 07, 2009 7:45 PM, David Freedman wrote: > ...how about: > d=data[order(data$ID,-data$Type),] > d[!duplicated(d$ID),] Does the "-data$Type" argument to the order function work? -- David   - David Huffer, Ph.D.

Re: [R] by-group processing

2009-05-07 Thread David Freedman
how about: d=data[order(data$ID,-data$Type),] d[!duplicated(d$ID),] Max Webber wrote: > > Given a dataframe like > > > data > ID Type N > 1 45900A 1 > 2 45900B 2 > 3 45900C 3 > 4 45900D 4 > 5 45900E 5 > 6 45900F 6 > 7 45900I 7 > 8

Re: [R] by-group processing

2009-05-07 Thread William Dunlap
ill Dunlap TIBCO Software Inc - Spotfire Division wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Max Webber > Sent: Wednesday, May 06, 2009 3:09 PM > To: r-help@r-project.org > Subject: [R

Re: [R] by-group processing

2009-05-06 Thread jim holtman
Ths should do it: > do.call(rbind, lapply(split(x, x$ID), tail, 1)) ID Type N 45900 45900I 7 46550 46550I 7 49270 49270E 3 On Wed, May 6, 2009 at 6:09 PM, Max Webber wrote: > Given a dataframe like > > > data >ID Type N > 1 45900A 1 > 2 45900B 2 > 3

Re: [R] by-group processing

2009-05-06 Thread Jorge Ivan Velez
Dear Max, By using "d" instead of "data" for your data set, here is one way: # First order the data by ID d <- with(d, d[order(ID),] ) # Then use tapply to get the indexes for the maximum values d[cumsum(with(d, tapply(N, ID, which.max))),] # ID Type N # 7 45900I 7 # 24 46550I 7 # 10 492

[R] by-group processing

2009-05-06 Thread Max Webber
Given a dataframe like > data ID Type N 1 45900A 1 2 45900B 2 3 45900C 3 4 45900D 4 5 45900E 5 6 45900F 6 7 45900I 7 8 49270A 1 9 49270B 2 10 49270E 3 18 46550A 1 19 46550B 2 20 46550C 3 21 46550