Output list of comma separated strings in R

Viewed 35

I was wondering if there is a quick way to do the following in R:

Given a list input of say:

input = c(1234,2394,2212)

which are all numeric say, is it possible to get an output of:

output = ('1234', '2394', '2212')

i.e., printed to the R console as a list of strings with single quotes.

1 Answers

We can use

as.character(input)

Or if we need a single string

out <- toString(sQuote(as.character(input), FALSE))
cat(out, "\n")
'1234', '2394', '2212' 
Related