[R] pull stat out of summary

David L Carlson dcarlson at tamu.edu
Sat Apr 1 01:58:34 CEST 2017


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 <r-help-bounces at r-project.org> on behalf of Evan Cooch <evan.cooch at gmail.com>
Sent: Friday, March 31, 2017 6:11 PM
To: r-help at r-project.org
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...

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



More information about the R-help mailing list