pull stat out of summary

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

pull stat out of summary

Evan Cooch
Continuing my learning curve after 25_ years with using SAS. Want to
pull the "Mean" forom the summary of something...

test <- rnorm(1000,1.5,1.25)

hold <- summary(test)

names(hold)
[1] "Min."    "1st Qu." "Median"  "Mean"    "3rd Qu." "Max."

OK, so "Mean" is in there.
So, is there a short form answer for why hold$Mean throws an error, and
hold["Mean"} returns the mean (as desired)?

Silly question I know,  but gotta start somewhere...

Thanks...

______________________________________________
[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: pull stat out of summary

Sarah Goslee
The short answer is that hold isn't a list-like object, and $ only
works with list-like objects (lists and data frames, mainly).

You can get the full explanation (VERY full), at
?Extract
or any of its aliases, like
?'$'
or
?'['

Sarah

On Fri, Mar 31, 2017 at 7:11 PM, Evan Cooch <[hidden email]> wrote:

> Continuing my learning curve after 25_ years with using SAS. Want to pull
> the "Mean" forom the summary of something...
>
> test <- rnorm(1000,1.5,1.25)
>
> hold <- summary(test)
>
> names(hold)
> [1] "Min."    "1st Qu." "Median"  "Mean"    "3rd Qu." "Max."
>
> OK, so "Mean" is in there.
> So, is there a short form answer for why hold$Mean throws an error, and
> hold["Mean"} returns the mean (as desired)?
>
> Silly question I know,  but gotta start somewhere...
>
> Thanks...
>

--
Sarah Goslee
http://www.functionaldiversity.org

______________________________________________
[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: pull stat out of summary

David Carlson
In reply to this post by Evan Cooch
This is your answer:

> str(hold)
Classes 'summaryDefault', 'table'  Named num [1:6] -2.602 0.636 1.514 1.54 2.369 ...
  ..- attr(*, "names")= chr [1:6] "Min." "1st Qu." "Median" "Mean" ...

hold is a table of named numbers, i.e. a vector with a names attribute. It is not a data.frame so it does not have column names. The error message sort of tells you this when it says hold is an atomic vector (i.e. not a list or a data frame which are built from other objects such as vectors).

David Carlson
Anthropology Department
Texas A&M University
________________________________________
From: R-help <[hidden email]> on behalf of Evan Cooch <[hidden email]>
Sent: Friday, March 31, 2017 6:11 PM
To: [hidden email]
Subject: [R] pull stat out of summary

Continuing my learning curve after 25_ years with using SAS. Want to
pull the "Mean" forom the summary of something...

test <- rnorm(1000,1.5,1.25)

hold <- summary(test)

names(hold)
[1] "Min."    "1st Qu." "Median"  "Mean"    "3rd Qu." "Max."

OK, so "Mean" is in there.
So, is there a short form answer for why hold$Mean throws an error, and
hold["Mean"} returns the mean (as desired)?

Silly question I know,  but gotta start somewhere...

Thanks...

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

______________________________________________
[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: pull stat out of summary

Bert Gunter-2
In reply to this post by Sarah Goslee
?str

tells you the structure of any object. *Learn to use it!*

It may well be the that you *cannot* do what you describe. As you
should know by now in your "learning curve", invoking

> obj

at the console silently invokes the print method for obj, and what is
printed may in fact be calculated on the fly in the print method and
not stored in an object anywhere.

?print.summary.lm

is such an example:  p-values are calculated and printed, but not stored.


Cheers,
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 Fri, Mar 31, 2017 at 4:54 PM, Sarah Goslee <[hidden email]> wrote:

> The short answer is that hold isn't a list-like object, and $ only
> works with list-like objects (lists and data frames, mainly).
>
> You can get the full explanation (VERY full), at
> ?Extract
> or any of its aliases, like
> ?'$'
> or
> ?'['
>
> Sarah
>
> On Fri, Mar 31, 2017 at 7:11 PM, Evan Cooch <[hidden email]> wrote:
>> Continuing my learning curve after 25_ years with using SAS. Want to pull
>> the "Mean" forom the summary of something...
>>
>> test <- rnorm(1000,1.5,1.25)
>>
>> hold <- summary(test)
>>
>> names(hold)
>> [1] "Min."    "1st Qu." "Median"  "Mean"    "3rd Qu." "Max."
>>
>> OK, so "Mean" is in there.
>> So, is there a short form answer for why hold$Mean throws an error, and
>> hold["Mean"} returns the mean (as desired)?
>>
>> Silly question I know,  but gotta start somewhere...
>>
>> Thanks...
>>
>
> --
> Sarah Goslee
> http://www.functionaldiversity.org
>
> ______________________________________________
> [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.

______________________________________________
[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: pull stat out of summary

Peter Dalgaard-2
In reply to this post by Sarah Goslee

> On 01 Apr 2017, at 01:54 , Sarah Goslee <[hidden email]> wrote:
>
> The short answer is that hold isn't a list-like object, and $ only
> works with list-like objects (lists and data frames, mainly).
>
> You can get the full explanation (VERY full), at
> ?Extract
> or any of its aliases, like
> ?'$'
> or
> ?'['
>

...and the intermediate answer is: hold["Mean"]

-pd

> Sarah
>
> On Fri, Mar 31, 2017 at 7:11 PM, Evan Cooch <[hidden email]> wrote:
>> Continuing my learning curve after 25_ years with using SAS. Want to pull
>> the "Mean" forom the summary of something...
>>
>> test <- rnorm(1000,1.5,1.25)
>>
>> hold <- summary(test)
>>
>> names(hold)
>> [1] "Min."    "1st Qu." "Median"  "Mean"    "3rd Qu." "Max."
>>
>> OK, so "Mean" is in there.
>> So, is there a short form answer for why hold$Mean throws an error, and
>> hold["Mean"} returns the mean (as desired)?
>>
>> Silly question I know,  but gotta start somewhere...
>>
>> Thanks...
>>
>
> --
> Sarah Goslee
> http://www.functionaldiversity.org
>
> ______________________________________________
> [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.

--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: [hidden email]  Priv: [hidden email]

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