I have mydata$var and I have mydata$group #two group I would like to split mydata$var by mydata$group #to get var1 and var2 And then get summary (var1, var2) #this is my finite aim How to encode it all?
?ave Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Mon, Dec 23, 2019 at 6:57 AM Medic <mailiPadpost at gmail.com> wrote:> I have > mydata$var > > and I have > mydata$group #two group > > I would like to split > mydata$var > by > mydata$group #to get var1 and var2 > > And then get > summary (var1, var2) #this is my finite aim > > How to encode it all? > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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]]
Not clear what you mean by summary (var1, var2) ? That is not a legal way to call summary. Perhaps mt <- mtcars[,c("cyl","hp")] mt$cyl <- factor( mt$cyl ) mtl <- split(mt[,"hp",drop=FALSE], mt$cyl) lapply(mtl,summary) On December 23, 2019 6:56:35 AM PST, Medic <mailiPadpost at gmail.com> wrote:>I have >mydata$var > >and I have >mydata$group #two group > >I would like to split >mydata$var >by >mydata$group #to get var1 and var2 > >And then get >summary (var1, var2) #this is my finite aim > >How to encode it all? > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >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.-- Sent from my phone. Please excuse my brevity.
On Mon, 23 Dec 2019 17:56:35 +0300 Medic <mailiPadpost at gmail.com> wrote:> I would like to split > mydata$var > by > mydata$group #to get var1 and var2There is the split() function that does exactly that (except it returns a list instead of multiple variables)...> And then get > summary (var1, var2) #this is my finite aim...and you can either use lapply() on the list returned by split() or tapply() to both split the dataset into groups and call summary() on each in one expression. See ?tapply and example(tapply) for more info. -- Best regards, Ivan
If I understand correctly you need summary by group. I would suggest arsenal package and tableby tab1 <- tableby(group ~ anova(var, "meansd", digits=1) + #mean and sd + round to 1 digit + anova kwt(var, "medianq1q3", digits=1) , #median q1 and q3 + round to 1 digit + Kruskal-Wallis data=sn.l.v2.t0) summary(tab1,text=TRUE) #output as txt to console write2word(tab1,"tab1.docx", pfootnote=TRUE) #save as formatted word table or even simpler using Rcmdr - Statistics - Numerical summaries and tha choose summarize by groups Milos On Mon, 23 Dec 2019 at 15:57, Medic <mailiPadpost at gmail.com> wrote:> I have > mydata$var > > and I have > mydata$group #two group > > I would like to split > mydata$var > by > mydata$group #to get var1 and var2 > > And then get > summary (var1, var2) #this is my finite aim > > How to encode it all? > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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]]