Split

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Split

Medic
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?

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Split

Bert Gunter-2
?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 <[hidden email]> 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?
>
> ______________________________________________
> [hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Split

Jeff Newmiller
In reply to this post by Medic
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 <[hidden email]> 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?
>
>______________________________________________
>[hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Split

Ivan Krylov
In reply to this post by Medic
On Mon, 23 Dec 2019 17:56:35 +0300
Medic <[hidden email]> wrote:

> I would like to split
> mydata$var
> by
> mydata$group #to get var1 and var2

There 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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Split

Miloš Žarković
In reply to this post by Medic
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 <[hidden email]> 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?
>
> ______________________________________________
> [hidden email] 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]]

______________________________________________
[hidden email] 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.