Comma Seperate A String

Original code:

Want to learn more? I recommend working through: R for Data Science, R Cookbook, and R Graphics Cookbook.

# Create a text string
cities <- c("sonomanapahealdsburgoakland")
# A vector with the locations of where we want each comma
comma.locations <- c(6,4,10,7)
# Place the commas into the string according to the locations specifics in comma.locations
paste(read.fwf(textConnection(cities), comma.locations, = TRUE), collapse = ",")
[1] "sonoma,napa,healdsburg,oakland"