Creating a Comma Separated Character Vector in R Programming (Example Code)

This page shows how to create a vector separated by commas in the R programming language.

Introducing Example Data

my_vec <- 1:10                                                      # Creating numeric vector
my_vec                                                              # Printing vector
# 1  2  3  4  5  6  7  8  9 10

Example: Converting Example Vector to Comma Separated Format

my_vec_cs <- paste(shQuote(my_vec, type = "cmd"), collapse = ", ")  # Modify data
cat(my_vec_cs)                                                      # Comma separated character vector
# "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"

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

Menu
Top