Dear all, I have a simple question: How can I retrieve a list with all properties of an object? Example: If I fit a regression with model <- coxph(Surv(....)~...) I know that I can access the coefficients with model$coefficients[...] afterwards, but how do I know which other variables are available and what are their names? Thanks and all the best Philipp
On Feb 2, 2010, at 1:08 PM, Philipp Rappold wrote:> Dear all, > > I have a simple question: How can I retrieve a list with all > properties of an object? > > Example: > If I fit a regression with > > model <- coxph(Surv(....)~...) > > I know that I can access the coefficients with model > $coefficients[...] afterwards, but how do I know which other > variables are available and what are their names??str> > Thanks and all the best > Philipp-- David Winsemius, MD Heritage Laboratories West Hartford, CT
Philipp, Check ?str which displays the structure of R objects. And do use extractor functions when available: coef(yourModel) instead of yourModel$coef -Peter Ehlers Philipp Rappold wrote:> Dear all, > > I have a simple question: How can I retrieve a list with all properties > of an object? > > Example: > If I fit a regression with > > model <- coxph(Surv(....)~...) > > I know that I can access the coefficients with model$coefficients[...] > afterwards, but how do I know which other variables are available and > what are their names? > > Thanks and all the best > Philipp > > ______________________________________________ > R-help at r-project.org mailing list > 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 Ehlers University of Calgary
Others mentioned the str function which gives the full structure of the object and lots of information. If you just want the names of the top level elements then the names function is a little quicker and less cluttered (but does not give all the detail that str does). For large and/or complex objects you may want to look at the TkListView function in the TeachingDemos package. It gives the same information as str, but allows you to collapse or expand the branches of interest. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Philipp Rappold > Sent: Tuesday, February 02, 2010 11:09 AM > To: r-help at r-project.org > Subject: [R] List of object properties > > Dear all, > > I have a simple question: How can I retrieve a list with all > properties of an object? > > Example: > If I fit a regression with > > model <- coxph(Surv(....)~...) > > I know that I can access the coefficients with > model$coefficients[...] afterwards, but how do I know which other > variables are available and what are their names? > > Thanks and all the best > Philipp > > ______________________________________________ > R-help at r-project.org mailing list > 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.