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
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
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
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
-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
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
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
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
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
-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
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
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]
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,
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
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
Greetings R-ians:
I know what doesnt work but I dont 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
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
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
: 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
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
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,
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
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?
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
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
101 - 125 of 125 matches
Mail list logo