col.names <- strsplit("one, two, three", ", ")[[1]]
is an easy way to do this. But you can do
paste('"', gsub(', ', '","', "one,
two, three"), '"', sep="")
R accepts either single or double quotes and it can make life easier to
use both.
On Fri, 12 Aug 2005, Jean-Pierre Gattuso wrote:
> Hi:
>
> I have been struggling with gsub to no avail and am seeking help from
> the list.
>
> I want to make a vector of the string "one, two, three" and have
> tried to:
>
> - replace each comma by ","
> - add " at the beginning of the string
> - add " at the end of the string
>
> to issue the command:
>
> col.names <- c("one", "two", "three")
>
> for use in a data frame.
>
> I have tried gsub to get that but am unable to get the double quote
> and when I try to escape it (\"), I also get the backslash.
>
>
> Thanks for your help,
> jpg
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595