Hi Ista,

This is hat I thought I am doing

I forgot to mention, but I am working with a table which look like that:
>head(data)
id     protein_ids
45    FBpp0070037
46    FBpp0070039;FBpp0070040
47    FBpp0070041;FBpp0070042;FBpp0070043
48    FBpp0070044;FBpp0110571
...

For one line your solution works fine, but I would like to do it for the
complete column. I was trying ti use apply on the column, but I get no
output.

Do you have another idee?

Thanks
Assa

On Tue, Jan 24, 2012 at 13:11, Ista Zahn <istaz...@gmail.com> wrote:

> Hi Assa,
>
> On Tue, Jan 24, 2012 at 6:30 AM, Assa Yeroslaviz <fry...@gmail.com> wrote:
> > Hi,
> >
> > I would like to substitute a semicolon with two double quotation marks
> and
> > a comma inbetween.
> > It suppose to look like that:
> >
> > I have:
> > FBpp0070086;FBpp0099643;FBpp0112915
> > I would like to have:
> > "FBpp0070086","FBpp0099643","FBpp0112915"
> >
> > I tried with various numbers of backslashes, but noe have worked.
> > for example:
> > gsub(";", "\\\",\"", data$protein_ids)
> > gsub(";", "\\",\"", data$protein_ids)
> > gsub(";", "\",\"", data$protein_ids)
> This is actually the one you want. You may be getting confused by the
> fact that print does some formatting of strings, including enclosing
> them in quotes. To see what you've actually got here, try out the
> cat() function:
>
> x <- "FBpp0070086;FBpp0099643;FBpp0112915"
> cat(gsub(";", "\",\"", x))
> FBpp0070086","FBpp0099643","FBpp0112915
>
> So that's what you said you wanted, although I expect you also want
> quotes at the beginning and end of the vector. I also tend to
> alternate " and ' instead of escaping quotes (only works once of
> course, but usually that's all you need), so:
>
> cat(paste('"', gsub(";", '",\"', x), '"', sep = ""))
> "FBpp0070086","FBpp0099643","FBpp0112915"
>
> Best,
> Ista
>
>
>
> > gsub(";", "\\',\\'", data$protein_ids)
> > gsub(";", '"',data$protein_ids)
> >
> > What do I miss?
> >
> > Thanks
> > Assa
> >
> >        [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > 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.
>

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to