On Wed, Sep 29, 2010 at 4:15 AM, Steven Kang <stochastick...@gmail.com> wrote: > x <- rep(letters[1:3], 2) > > Are there any ways to transform & assign the above as the one shown below > to an object? (in exact format; i.e length of 1 & class of character), > i.e >>x > "('a', 'b', 'c', 'a', 'b', 'c')" > > Highly appreciate for any advice. >
Here are a few variations. They all use paste (or the paste0 wrapper) and toString. The last one uses sQuote to do the quoting, turning off fancy quotes so that ordinary single quotes are used. # 1 paste("(", toString(paste("'", x, "'", sep = "")), ")", sep = "") #2 library(gsubfn) # paste0 paste0("(", toString(paste0("'", x, "'")), ")") # 3 P <- function(x, pre = "'", post = pre) paste(pre, x, post, sep = "") P(toString(P(x)), "(", ")") # 4 old <- options(useFancyQuotes = FALSE) paste("(", toString(sQuote(x)), ")", sep = "") options(old) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.