(This article was first published on is.R(), and kindly contributed to R-bloggers)
As you advance in your R use past “canned” functions and packages made by others, you may want to take information from one R object for use in another.
For example, you may want to estimate a linear model, then use the results of that estimation to:
- Use coefficient values and the variance-covariance matrix to simulate from the model,
- Visualize model diagnostics, including the distribution of residuals,
- Feed into another model as prior information,
- Etc.
str() is a function that allows you to examine any R object, in order to “see what’s inside,” so to speak. In the case of a linear model produced by lm(), the model object (as well as the model summary object) is a list that contains a lot of information, permitting the assessment of model fit, diagnostic plotting, prediction, etc.
The following Gist is a rather unimaginative introduction to the use of str(), but as is often the case, simply knowing of its existence is of great use.
To leave a comment for the author, please follow the link and comment on their blog: is.R().
R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...