> For the complete documentation index, see [llms.txt](https://docs.redivis.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.redivis.com/api/client-libraries/redivis-r/reference/variable.md).

# Variable

## *class* <mark style="color:purple;">Variable</mark>

Variables represent the "columns" in tables (and uploads), and have certain metadata as well as detailed univariate summary statistics associated with them. Use this class to interface with variables and their metadata.

## Constructors

<table data-header-hidden><thead><tr><th width="342">Method</th><th>Description</th></tr></thead><tbody><tr><td><a href="/api/client-libraries/redivis-r/reference/query/queryusdlist_variables.md"><strong><code>Query$list_variables</code></strong></a>([max_results])</td><td>List all variables in a (completed) query's results.</td></tr><tr><td><a href="/api/client-libraries/redivis-r/reference/table/tableusdlist_variables.md"><strong><code>Table$list_variables</code></strong></a>([max_results])</td><td>List all variables in a table.</td></tr><tr><td><a href="/api/client-libraries/redivis-r/reference/upload/uploadusdlist_variables.md"><strong><code>Upload$list_variables</code></strong></a>([max_results])</td><td>List all variables in a (completed) upload.</td></tr><tr><td><a href="/api/rest-api/variables.md"><strong><code>Query$variable</code></strong></a>(variable_name)</td><td>Construct a reference to a variable within a completed query based on its (case-insensitive) name.</td></tr><tr><td><a href="/api/rest-api/variables.md"><strong><code>Table$variable</code></strong></a>(variable_name)</td><td>Construct a reference to a variable within a table based on its (case-insensitive) name.</td></tr><tr><td><a href="/api/rest-api/variables.md"><strong><code>Upload$variable</code></strong></a>(variable_name)</td><td>Construct a reference to a variable within a completed upload based on its (case-insensitive) name.</td></tr></tbody></table>

## Examples

{% tabs %}
{% tab title="Basics" %}

<pre class="language-r"><code class="lang-r">loadNamespace("redivis")

<strong>table &#x3C;- redivis$organization("Demo")$dataset("iris_species")$table("iris")
</strong>
variable &#x3C;- table$variable("sepalLengthCm")

variable$exists() # -> TRUE
variable$get() 

print(variable$properties)

{
	"kind": "variable",
	... (see variable resource definition)
}

print(variable$get_statistics())

{
  "kind": "variableStatistics"
  "status": "completed",
  "count": 150,
  "numDistinct": 35,
  "min": 4.3,
  "max": 7.9,
  "mean": 5.8433333333333355,
  "approxMedian": 0.8280661279778625,
  ...
}
</code></pre>

{% endtab %}
{% endtabs %}

## Attributes

| **`properties`** | A named list containing the [API resource representation of the variable](/api/resource-definitions/variable.md#base-definition). This will only be populated after certain methods are called, particularly the `get` method, and will otherwise be an empty list. |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`table`**      | A reference to the [Table](/api/client-libraries/redivis-r/reference/table.md) instance that constructed this variable. Will be `NULL` if the variable belongs to an upload.                                                                                        |

## Methods

<table data-header-hidden><thead><tr><th width="421">Name</th><th>Description</th></tr></thead><tbody><tr><td><a href="/api/client-libraries/redivis-r/reference/variable/variableusdget.md"><strong><code>variable$get</code></strong></a>()</td><td>Gets the variable, after which the <code>properties</code> attribute will be populated according to the <a href="/api/resource-definitions/variable.md#get-definition">variable.get resource definition.</a></td></tr><tr><td><a href="/api/client-libraries/redivis-r/reference/variable/variableusdget_statistics.md"><strong><code>variable$get_statistics</code></strong></a>()</td><td>Gets the variable statistics, returning a named list corresponding the <a href="/api/resource-definitions/variablestatistics.md">variableStatistics resource definition.</a></td></tr><tr><td><a href="/api/client-libraries/redivis-r/reference/variable/variableusdexists.md"><strong><code>variable$exists</code></strong></a>()</td><td>List all visible datasets owned by the user.</td></tr><tr><td><a href="/api/client-libraries/redivis-r/reference/variable/variableusdupdate.md"><strong><code>variable$update</code></strong></a>([label, description, ...])</td><td>Update a variable's metadata.</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.redivis.com/api/client-libraries/redivis-r/reference/variable.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
