Skip to content

quotes

2 messages · Jean-Pierre Gattuso, Brian Ripley

#
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
#
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: