How to Extract Names & First Row of table() in R (2 Examples)

This page illustrates how to extract the first row and the table names from a table() object in R.

Creation of Exemplifying Data

data(iris)                         # Load data
tab_iris <- table(iris$Species)    # Create example table
tab_iris                           # Display example table in RStudio console
#     setosa versicolor  virginica 
#         50         50         50

Example 1: Get Names of Table

names(tab_iris)                    # Display table names
# [1] "setosa"     "versicolor" "virginica"

Example 2: Get Values of Table

as.numeric(tab_iris)               # Display table values
# [1] 50 50 50

Further Resources & Related Tutorials

In the following, you can find some further resources on topics such as extracting data, numeric values, and matrices:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed