Re: [R] quotes

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Sat 13 Aug 2005 - 07:39:00 EST

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

______________________________________________
R-help@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
Received on Sat Aug 13 07:49:27 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:18:06 EST