Create Variable Name Using paste() Function in R (Example)

 

In this tutorial you’ll learn how to create a new variable using the paste() function in the R programming language.

The table of content is structured as follows:

With that, let’s take a look at some R codes in action!

 

Example: Create Variable Name with paste0() & assign() Functions

This Example explains how to apply the paste0 and assign functions to define a new variable in R.

assign(paste0("variable_", 1), 1:5)    # Using assign function

Let’s have a look at the output:

variable_1                             # Return new variable to console
# 1 2 3 4 5

As you can see based on the previous output of the RStudio console, we have created a new vector object called variable_1.

 

Video, Further Resources & Summary

Would you like to learn more about pasting variable names? Then you could watch the following video of my YouTube channel. In the video, I illustrate the R programming syntax of this tutorial.

 

The YouTube video will be added soon.

 

In addition, you could read the related posts of this homepage. I have published several tutorials already.

 

Summary: At this point you should have learned how to apply the paste function to create a new variable name in R. Please let me know in the comments, in case you have further questions.

 

Subscribe to my free statistics newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.


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.

Menu
Top