Using paste() Function to Create New Variable in R (Example Code)

In this R programming tutorial you’ll learn how to apply the paste function to create a new variable name.

Example: Creating New Variable Using paste0() & assign()

assign(paste0("x", 1), 100:110)    # Applying assign & paste0
x1                                 # Printing variable to RStudio console
#  [1] 100 101 102 103 104 105 106 107 108 109 110

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