Split

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

Split

Medic
I have
mydata$var
#this is ONE group of patients

And I would like to get
median and ICR of mydata$var.

How can I get this?
With summary (mydata$var)!

Ok!

And now I would like to get THE SAME, but for TWO group: male and
female (which are contained in the group mydata$var)

How can I get this?
First I need to split mydata$var by mydata$sex, and then take:

summary (for male)
and
summary (for female)

That's all I want

Bert,
ave(mydata$var, madata$sex, FUN=median)
gives me:
[1] 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6
5.6 5.6 5.6 5.6
[21] 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0
6.0 6.0 6.0 6.0
What is it?
It is an endless(???) repetition of the median.
Moreover, there is no ICR.

Jeff,
your constructions are too complicated for me
===
P.S. Such simple thing and so difficult?! (I begin think about the Excel.)

______________________________________________
[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
Do you mean IQR? -- I don't know what ICR means.
If so, see IQR.

More generally see ?by or more generally ?tapply to obtain whatever sort of
summary you want.

e.g.

> d <-data.frame( x = runif(10), w = rep(c("a","b"),5))
> by(d$x, d$w, FUN = function(x)c(median = median(x),IQR = IQR(x)))
d$w: a
   median       IQR
0.5469662 0.4548506
--------------------------------------------------------------
d$w: b
   median       IQR
0.6860975 0.3456893


-- Bert
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 9:15 AM Medic <[hidden email]> wrote:

> I have
> mydata$var
> #this is ONE group of patients
>
> And I would like to get
> median and ICR of mydata$var.
>
> How can I get this?
> With summary (mydata$var)!
>
> Ok!
>
> And now I would like to get THE SAME, but for TWO group: male and
> female (which are contained in the group mydata$var)
>
> How can I get this?
> First I need to split mydata$var by mydata$sex, and then take:
>
> summary (for male)
> and
> summary (for female)
>
> That's all I want
>
> Bert,
> ave(mydata$var, madata$sex, FUN=median)
> gives me:
> [1] 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6
> 5.6 5.6 5.6 5.6
> [21] 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0
> 6.0 6.0 6.0 6.0
> What is it?
> It is an endless(???) repetition of the median.
> Moreover, there is no ICR.
>
> Jeff,
> your constructions are too complicated for me
> ===
> P.S. Such simple thing and so difficult?! (I begin think about the Excel.)
>
> ______________________________________________
> [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

Miloš Žarković
J have just seen your follow-up post (out of tread). I don’t want to be
rude or patronizing but few caveats.

Neither R nor R help are meant to be user friendly. Learning curve is steep
but very rewarding at the end.

Problem you have can be solved in a literary hundred ways. Unfortunately,
your question was not a reproducible example and you got most complicated
answer. Apply entourage is kind of dark art in R, so I offered different
solutions, and hope that my answer helped.

Being medic too, I understand your pain, but for the star I suggest Rcmdr.


Regards,


Miloš


On Mon, 23 Dec 2019 at 20:36, Bert Gunter <[hidden email]> wrote:

> Do you mean IQR? -- I don't know what ICR means.
> If so, see IQR.
>
> More generally see ?by or more generally ?tapply to obtain whatever sort of
> summary you want.
>
> e.g.
>
> > d <-data.frame( x = runif(10), w = rep(c("a","b"),5))
> > by(d$x, d$w, FUN = function(x)c(median = median(x),IQR = IQR(x)))
> d$w: a
>    median       IQR
> 0.5469662 0.4548506
> --------------------------------------------------------------
> d$w: b
>    median       IQR
> 0.6860975 0.3456893
>
>
> -- Bert
> 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 9:15 AM Medic <[hidden email]> wrote:
>
> > I have
> > mydata$var
> > #this is ONE group of patients
> >
> > And I would like to get
> > median and ICR of mydata$var.
> >
> > How can I get this?
> > With summary (mydata$var)!
> >
> > Ok!
> >
> > And now I would like to get THE SAME, but for TWO group: male and
> > female (which are contained in the group mydata$var)
> >
> > How can I get this?
> > First I need to split mydata$var by mydata$sex, and then take:
> >
> > summary (for male)
> > and
> > summary (for female)
> >
> > That's all I want
> >
> > Bert,
> > ave(mydata$var, madata$sex, FUN=median)
> > gives me:
> > [1] 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6 5.6
> > 5.6 5.6 5.6 5.6
> > [21] 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0 6.0
> > 6.0 6.0 6.0 6.0
> > What is it?
> > It is an endless(???) repetition of the median.
> > Moreover, there is no ICR.
> >
> > Jeff,
> > your constructions are too complicated for me
> > ===
> > P.S. Such simple thing and so difficult?! (I begin think about the
> Excel.)
> >
> > ______________________________________________
> > [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.
>

        [[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.