Re: [R] gsub patterns from vector elements w/out loop?

2010-02-22 Thread Marc Schwartz
On Feb 22, 2010, at 10:25 AM, Marianne Promberger wrote: Dear list, I have two vectors: x - c(one,two) y - paste(rep(x,2),blah) I want to replace all occurrences of each element of x in y with something else, so that y looks like this: y [1] something else blah something else

Re: [R] gsub patterns from vector elements w/out loop?

2010-02-22 Thread Marianne Promberger
gsub(paste(x, collapse = |), something else, y) [1] something else blah something else blah something else blah [4] something else blah Many thanks! I didn't know about collapse. Should have thought about reading up in ?paste ... Thanks Marianne -- Marianne Promberger PhD, King's

Re: [R] gsub patterns from vector elements w/out loop?

2010-02-22 Thread Christian Raschke
Marianne, The function substring2 from the Hmisc packages works nicely for me to do this (without explicit gsub, though): x- c(one,two) y- paste(rep(x,2),blah) y [1] one blah two blah one blah two blah substring2(y,x)- something else y [1] something else blah something else blah something

Re: [R] gsub patterns from vector elements w/out loop?

2010-02-22 Thread Gabor Grothendieck
Here are a few possibilities using gsubfn in the gsubfn package x - c(one,two) y - paste(rep(x,2),blah) library(gsubfn) # 1 gsubfn(\\w+, w ~ if (w %in% x) something else else w, y) # 2 gsubfn(\\w+, list(one = something else, two = something else), y) # 3 L - sapply(x, function(...) something

Re: [R] gsub patterns from vector elements w/out loop?

2010-02-22 Thread Bert Gunter
-help-boun...@r-project.org] On Behalf Of Christian Raschke Sent: Monday, February 22, 2010 10:20 AM To: r-help@r-project.org Subject: Re: [R] gsub patterns from vector elements w/out loop? Marianne, The function substring2 from the Hmisc packages works nicely for me to do this (without explicit

Re: [R] gsub does not support \b?

2009-11-11 Thread Uwe Ligges
Tan, Richard wrote: Hello, can someone help? How come gsub(\bINDS\b,INDUSTRIES,ADVANCED ENERGY INDS) [1] ADVANCED ENERGY INDS It does, but you need to escape it: gsub(\\bINDS\\b,INDUSTRIES,ADVANCED ENERGY INDS) Uwe Ligges not ADVANCED ENERGY INDUSTRIES Thanks. Richard

[R] gsub does not support \b?

2009-11-10 Thread Tan, Richard
Hello, can someone help? How come gsub(\bINDS\b,INDUSTRIES,ADVANCED ENERGY INDS) [1] ADVANCED ENERGY INDS not ADVANCED ENERGY INDUSTRIES Thanks. Richard [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

Re: [R] gsub does not support \b?

2009-11-10 Thread Tan, Richard
Ok, I figured it out. My stupid mistake, should be \\b instead of \b. From: Tan, Richard Sent: Tuesday, November 10, 2009 3:36 PM To: 'r-help@r-project.org' Subject: gsub does not support \b? Hello, can someone help? How come

[R] gsub - replace multiple occurences with different strings

2009-10-05 Thread Martin Batholdy
Hi, I search a way to replace multiple occurrences of a string with different strings depending on the place where it occurs. I tried the following; x - c(xx y e d xx e t f xx e f xx) x - gsub(xx, c(x1, x2, x3, x4), x) what I want to get is; x = x1 y y e d x2 e t f x3 e f x4 but what I

Re: [R] gsub - replace multiple occurences with different strings

2009-10-05 Thread William Dunlap
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Martin Batholdy Sent: Monday, October 05, 2009 7:34 AM To: r help Subject: [R] gsub - replace multiple occurences with different strings Hi, I search a way to replace

Re: [R] gsub - replace multiple occurences with different strings

2009-10-05 Thread Gabor Grothendieck
05, 2009 7:34 AM To: r help Subject: [R] gsub - replace multiple occurences with different strings Hi, I search a way to replace multiple occurrences of a string with different strings depending on the place where it occurs. I tried the following; x - c(xx y e d xx e t f xx e f xx) x

[R] gsub and regex to tidy comma-limited values

2009-03-14 Thread Daren Tan
I am cleaning up comma-limited values, so that only one comma separates each value. Using the example below, as much as I try with regex, I can't remove the last comma. I hope to have a one-liner solution, if possible. gsub(^,*|,*$|(,)*, \\1, ,,,apple,,orange,lemon,strawberry) [1]

Re: [R] gsub and regex to tidy comma-limited values

2009-03-14 Thread Gabor Grothendieck
Add perl = TRUE On Sat, Mar 14, 2009 at 5:42 AM, Daren Tan darenta...@gmail.com wrote: I am cleaning up comma-limited values, so that only one comma separates each value. Using the example below, as much as I try with regex, I can't remove the last comma. I hope to have a one-liner solution,

Re: [R] gsub and regex to tidy comma-limited values

2009-03-14 Thread Tom
sub(,$,,gsub(^,*|,*$|(,)*, \\1, ,,,apple,,orange,lemon,strawberry)) It may not be the best solution, but it was my first thought Tom - Original Message - From: Daren Tan darenta...@gmail.com To: r-help@r-project.org Sent: Saturday, March 14, 2009 6:42 PM Subject: [R] gsub

Re: [R] gsub and regex to tidy comma-limited values

2009-03-14 Thread Wacek Kusnierczyk
solution, but it was my first thought Tom - Original Message - From: Daren Tan darenta...@gmail.com To: r-help@r-project.org Sent: Saturday, March 14, 2009 6:42 PM Subject: [R] gsub and regex to tidy comma-limited values I am cleaning up comma-limited values, so that only one comma

[R] gsub difficulty

2008-09-23 Thread Charles Annis, P.E.
Greetings R-ians: I know what doesn’t work but I don’t know why, nor how to remedy things. I have a character string containing . which I want to replace with gsub(., , file.label) replaces the every character with a blank. However gsub(.xls, , file.label) replaces .xls with a blank as

Re: [R] gsub difficulty

2008-09-23 Thread Marc Schwartz
on 09/23/2008 12:16 PM Charles Annis, P.E. wrote: Greetings R-ians: I know what doesn’t work but I don’t know why, nor how to remedy things. I have a character string containing . which I want to replace with gsub(., , file.label) replaces the every character with a blank. However

Re: [R] gsub difficulty

2008-09-23 Thread Charles Annis, P.E.
Thanks! Charles Annis, P.E. [EMAIL PROTECTED] phone: 561-352-9699 eFax: 614-455-3265 http://www.StatisticalEngineering.com -Original Message- From: Phil Spector [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 23, 2008 1:30 PM To: Charles Annis, P.E. Subject: Re: [R] gsub

Re: [R] gsub difficulty

2008-09-23 Thread Charles Annis, P.E.
: Tuesday, September 23, 2008 2:21 PM To: [EMAIL PROTECTED] Subject: Re: [R] gsub difficulty Dear Charles, Phil Spector answered your original question by using two different approaches, but here I'm going again :) x=your.string.is.here gsub([.], ,x) [1] your string is here HTH

[R] gsub and \

2008-07-09 Thread Sean Davis
This is hopefully a simple question. I am trying to escape single quotes like so: abc'sabc\'s However, I cannot find an easy way to do that with gsub: gsub(',',abc's) # returns abc\\'s How can I get a single \ in the output? Thanks, Sean

Re: [R] gsub and \

2008-07-09 Thread jim holtman
It does have a single \; the printing just shows that it is escaped. If you 'cat' it to output, you will see: gsub(',',abc's) [1] abc\\'s cat(gsub(',',abc's)) abc\'s Which I think is what you were thinking it would be. So when you write it out to a file, it will be correct. On Wed,

Re: [R] gsub and \

2008-07-09 Thread Sean Davis
On Wed, Jul 9, 2008 at 11:57 AM, jim holtman [EMAIL PROTECTED] wrote: It does have a single \; the printing just shows that it is escaped. If you 'cat' it to output, you will see: gsub(',',abc's) [1] abc\\'s cat(gsub(',',abc's)) abc\'s Which I think is what you were thinking it

Re: [R] gsub and \

2008-07-09 Thread Ted Harding
On 09-Jul-08 15:49:54, Sean Davis wrote: This is hopefully a simple question. I am trying to escape single quotes like so: abc'sabc\'s However, I cannot find an easy way to do that with gsub: gsub(',',abc's) # returns abc\\'s How can I get a single \ in the output?

[R] gsub and multiple replacements

2008-06-02 Thread Ng Stanley
Hi, I would like to replace A B by A-B and AA(DD) by AA using a single gsub. Is that possible besides using two gsub ? Thanks Stanley [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

Re: [R] gsub and multiple replacements

2008-06-02 Thread Hans-Jörg Bibiko
On 02.06.2008, at 17:27, Ng Stanley wrote: I would like to replace A B by A-B and AA (DD) by AA using a single gsub. Is that possible besides using two gsub ? Could you be a bit more precisely? If you are dealing with two fix strings then you can write

<    1   2