Extract Column of dplyr Tibble in R (Example)
This article shows how to extract a certain tibble column as vector in R.
The article will consist of the following contents:
Let’s dive right in:
Creation of Example Data
If we want to work with tibbles, we first need to install and load the dplyr package in R:
install.packages("dplyr") # Install dplyr package library("dplyr") # Load dplyr package
Now, we can create an example tibble as shown below:
data <- data.frame(x1 = 1:5, # Create example tibble x2 = letters[1:5], x3 = 1) data <- as_tibble(data) data # Print example tibble # # A tibble: 5 x 3 # x1 x2 x3 # <int> <fct> <dbl> # 1 a 1 # 2 b 1 # 3 c 1 # 4 d 1 # 5 e 1
Our example tibble contains of three columns and five rows.
Example: Extract Column from tbl
If we want to select a specific column of our tibble and convert it to a vector, we can use the pull function:
x1 <- data %>% pull(x1) # Extract column from tibble x1 # Print column to console # 1 2 3 4 5
As you can see based on the RStudio console output, we extracted the column x1 from our tibble and created a new vector with the name x1.
Video & Further Resources
I have recently published a video on my YouTube channel, which illustrates the topics of this tutorial. You can find the video below.
Also, you could read the related articles on my homepage. Some tutorials about dplyr and similar R packages can be found here:
- Extract Certain Columns of Data Frame
- pull R Function of dplyr Package
- Print Entire tibble to R Console
- dplyr Package Tutorial
- The R Programming Language
Summary: This tutorial illustrated how to convert a tibble variable to a vector in R programming. Let me know in the comments section, if you have any further questions. Furthermore, please subscribe to my email newsletter in order to receive regular updates on new tutorials.
Subscribe to the Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.
Thank you!
Welcome to the Statistics Globe newsletter. From now on, I’ll send you regular emails about statistics, data science, AI, and programming with R and Python.
I’m Joachim Schork. On this website, I provide statistics tutorials as well as code in Python and R programming.
Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe. I hate spam & you may opt out anytime: Privacy Policy.
Thank you!
Please check your email inbox and click the confirmation link to complete your subscription. If you don’t see the email within a few minutes, please also check your spam/junk folder.






