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 |
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" |
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"