## Introduction

This article describes how to extract data from a *Standard R* object in Displayr:

R analyses that are "built-in" to Displayr are referred to as *Standard R*. These are analyses where the R code has been connected to a graphical user interface (GUI) via the menu and include pre-written R code.

## Requirements

A built-in R-based analysis object such as a regression, visualization, or segmentation output. In this example we are using a regression output with the **Name** of *glm*. You find the **Name **under **Properties > GENERAL **in the **object inspector**.

## Method

In order to extract data from an R object such as a regression output, we need to know a bit more information about its structure.

The simplest way to do this is to create a new Calculation via **Calculation > Custom Code** containing the code: `names(glm)`

.

The result contains a table that tells us what objects are contained within *glm*.

## Using index

We can see that the 5th item is **n.predictors**. So, we can extract this item `glm[5]`

.

However, when we do this we get a bit of baggage with it. Rather than just getting the result, we are also getting the name as well. If we just want the result, we instead use `glm[[5]]`

:

Objects contained within the output can have sub-objects (i.e., there is a hierarchy of objects). To access objects that reside in other objects, we can use `names(glm[[19]])`

. The result will reveal the names of the items in the 17th item of *glm*, which is the summary. We can see that the 9th item is **adj.r.squared**. This means that to extract the *adjusted R-squared* statistic we could use `glm[[9]][[19]]`

and get the below (after increasing the number of decimals):

## Using $

The example above is a bit messy, however. If you type `glm[[9]][[19]]`

instead of `glm[[19]][[9]]`

you will get a different answer, but you may not spot it. Fortunately, we can instead reference parts of an object by name. For example: `glm$summary$adj.r.squared`

This example uses $ to extract the whole table of coefficients.

Note, as the table of coefficients is also the final visualized data, this can also be referenced using the *attributes* function:

attributes(glm)[["ChartData"]]

While in most cases the *names* function will be sufficient to extract the relevant information from your output, the *attributes* function can also extract the output *class*, and, if a visualization, the chart type, chart data and various other chart settings.

## Using index and $ together

We can combine subscripting with using $. For example, we could extract all the standard errors from the regression model above by typing `glm$summary$coefficients[, 2]`

or, equivalently, ```
glm$summary$coefficients[, "Std.
Error"]
```

.

By having nothing before the comma in the bracket, it returns all the rows. By specifying just the column in the bracket, it returns just that column. And, do note that the actual text we have used here instead of *Std. Error* is actually a bit different to that used in the original output table at the top (*Standard Error*). The original table has been formatted for readability.

## See Also

How to Extract Data from a Single Column Summary Table

How to Extract Data from a Multiple Column Table

How to Extract Data from a Multiple Column Table with Multiple Statistics

How to Extract Data from a Multiple Column Table with Nested Data

How to Change Table Attributes in R Tables

How to Work with R in Displayr

## Comments

0 comments

Article is closed for comments.