Re: [R] gsub issue with consecutive pattern finds

2024-03-01 Thread Bert Gunter
> > > Thank you. Further, very nice solution. > > > > Best, > > > > Iago > > > > On 01/03/2024 12:49, Iris Simmons wrote: > > > Hi Iago, > > > > > > > > > This is not a bug. It is expected. Patterns may not overlap. H

Re: [R] gsub issue with consecutive pattern finds

2024-03-01 Thread Bert Gunter
at 3:59 AM Iago Giné Vázquez wrote: > > Hi Iris, > > Thank you. Further, very nice solution. > > Best, > > Iago > > On 01/03/2024 12:49, Iris Simmons wrote: > > Hi Iago, > > > > > > This is not a bug. It is expected. Patterns may not overlap. H

Re: [R] gsub issue with consecutive pattern finds

2024-03-01 Thread Iago Giné Vázquez
Hi Iris, Thank you. Further, very nice solution. Best, Iago On 01/03/2024 12:49, Iris Simmons wrote: > Hi Iago, > > > This is not a bug. It is expected. Patterns may not overlap. However, there > is a way to get the result you want using perl: > > ```R > gsub("

Re: [R] gsub issue with consecutive pattern finds

2024-03-01 Thread Iris Simmons
Hi Iago, This is not a bug. It is expected. Patterns may not overlap. However, there is a way to get the result you want using perl: ```R gsub("([aeiouAEIOU])(?=[aeiouAEIOU])", "\\1_", "aerioue", perl = TRUE) ``` The specific change I made is called a positiv

[R] gsub issue with consecutive pattern finds

2024-03-01 Thread Iago Giné Vázquez
Hi all, I tested next command: gsub("([aeiouAEIOU])([aeiouAEIOU])", "\\1_\\2", "aerioue") with the following output: [1] "a_eri_ou_e" So, there are two consecutive vowels where an underscore is not added. May it be a bug? Is it expected (bug or not)? Is there any chance to get what I want (a

Re: [R] gsub() could not replace my string

2016-10-07 Thread William Dunlap via R-help
; Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Oct 7, 2016 at 12:58 PM, Christofer Bogaso < bogaso.christo...@gmail.com> wrote: > Hello again, > > I have few many string elements, and some of those elements contain a > special phrase as '"[NA]NA%", whi

[R] gsub() could not replace my string

2016-10-07 Thread Christofer Bogaso
Hello again, I have few many string elements, and some of those elements contain a special phrase as '"[NA]NA%", which I planned to replace by some Blank. So I tried with below code in R > gsub("[NA]NA%", "", "[NA]NA%abcde") [1] "[NA]NA%abcde

Re: [R] gsub: replacing slashes in a string

2016-09-14 Thread Joe Ceradini
Thanks Jim! Joe On Wed, Sep 14, 2016 at 11:06 AM, jim holtman wrote: > try this: > > > gsub("", "/", test) > [1] "8/24/2016" "8/24/2016" "6/16/2016" "6/16/2016" > > > > > Jim Holtman > Data Munger Guru > > What is the problem that you are trying to solve? > Tell me what you want to do, not

Re: [R] gsub: replacing slashes in a string

2016-09-14 Thread jim holtman
try this: > gsub("", "/", test) [1] "8/24/2016" "8/24/2016" "6/16/2016" "6/16/2016" Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. On Wed, Sep 14, 2016 at 12:25 PM, Joe Ceradini wrote: > Hi all, > >

Re: [R] gsub: replacing slashes in a string

2016-09-14 Thread Joe Ceradini
ent of Anthropology > Texas A&M University > College Station, TX 77840-4352 > > > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Joe > Ceradini > Sent: Wednesday, September 14, 2016 11:25 AM > To: Zilefac > Subject: [R

Re: [R] gsub: replacing slashes in a string

2016-09-14 Thread David L Carlson
016" "2","8/24/2016" "3","6/16/2016" "4","6/16/2016" - David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message- From: R-help [

Re: [R] gsub: replacing slashes in a string

2016-09-14 Thread ruipbarradas
Hello, I failing to understand the problem, isn't the following what you want? (test2 <- gsub("\\", "/", test, fixed = TRUE)) [1] "8/24/2016" "8/24/2016" "6/16/2016" "6/16/2016" Hope this helps, Rui Barradas Citando Joe Ceradini : Hi all, There are many R help posts out there dealing with

[R] gsub: replacing slashes in a string

2016-09-14 Thread Joe Ceradini
Hi all, There are many R help posts out there dealing with slashes in gsub. I understand slashes are "escape characters" and thus need to be treated differently, and display differently in R. However, I'm still stuck on find-replace problem, and would appreciate any tips. Thanks! GOAL: replace al

Re: [R] gsub : replace regex pattern with values from another data.frame

2015-02-12 Thread arnaud gaboury
On Thu, Feb 12, 2015 at 7:12 PM, arnaud gaboury wrote: > On Thu, Feb 12, 2015 at 3:40 PM, arnaud gaboury > wrote: >> I have two df (and dt): >> >> df1 >> structure(list(name = c("poisonivy", "poisonivy", "poisonivy", >> "poisonivy", "poisonivy", "poisonivy", "poisonivy", "poisonivy", >> "cruzecon

Re: [R] gsub : replace regex pattern with values from another data.frame

2015-02-12 Thread arnaud gaboury
On Thu, Feb 12, 2015 at 3:40 PM, arnaud gaboury wrote: > I have two df (and dt): > > df1 > structure(list(name = c("poisonivy", "poisonivy", "poisonivy", > "poisonivy", "poisonivy", "poisonivy", "poisonivy", "poisonivy", > "cruzecontrol", "agreenmamba", "agreenmamba", "vairis", "vairis", > "vairis

[R] gsub : replace regex pattern with values from another data.frame

2015-02-12 Thread arnaud gaboury
I have two df (and dt): df1 structure(list(name = c("poisonivy", "poisonivy", "poisonivy", "poisonivy", "poisonivy", "poisonivy", "poisonivy", "poisonivy", "cruzecontrol", "agreenmamba", "agreenmamba", "vairis", "vairis", "vairis", "vairis", "vairis", "vairis", "xaeth"), text = c("ok", "need items

Re: [R] gsub regexp question

2014-10-15 Thread Jeff Newmiller
I believe the backslash is not considered an escape character by the extended RE library used by R (perl=FALSE), so it is being treated as a literal. This means that the last ] is outside the character class and is the atom that the * applies to. gsub("^([[:alnum:]\\[\\]]*).*", "\\1", "a]]]rra

[R] gsub regexp question

2014-10-15 Thread ALBERTO VIEIRA FERREIRA MONTEIRO
I just found a curious behaviour of regexp and I'd like to share with y'all. gsub("^([[:alnum:]\\[\\]]*).*", "\\1", "array[n] <- 10", perl=T) # works as expected ("array[n]") gsub("^([[:alnum:]\\[\\]]*).*", "\\1", "array[n] <- 10", perl=F) # doesn't work ("a") I didn't find anything in the docum

Re: [R] GSUB and Data.frame format lost

2014-08-19 Thread Ivan Calandra
Hi, If I understand you well, the problem is that DataGoogle2 is a 1-column data.frame and this is expected based on your code! I think you want something like this to change the 1st column of the data.frame: DataGoogle2 <- DataGoogle1 DataGoogle2$Campaña <- gsub("facebook-Ads1", "FBAds", Da

[R] GSUB and Data.frame format lost

2014-08-19 Thread Omar André Gonzáles Díaz
Hi all, please, i'm trying to understand how using "Gsub" for some search and replace of text, makes my data frame lost it's format. This is my code: DataGoogle1 <- read.csv(file = "DataGoogle2.csv", header = T, stringsAsFactors = F) head(DataGoogle1) Result 1: CampañaV

Re: [R] GSUB function and regex problem

2014-08-18 Thread Rui Barradas
Hello, Try reading your data with option stringsAsFactors = FALSE. It seems that your strings are being read as factors, which are coded as integers. DataGoogle1 <- read.csv(file = "DataGoogle2.csv", header = T, stringsAsFactors = FALSE) Hope this helps, Rui Barradas Em 18-08-2014 10:13,

Re: [R] GSUB function and regex problem

2014-08-18 Thread William Dunlap
gsub will work on a column of a data.frame, not an entire data.frame. > gsub(pattern = "facebook-Ads1", "FBAds", DataGoogle1$Campaña) [1] "FBAds" "faceBOOK-Ads1" "fcebook-ads12" "Email1" "mail1" [6] "referral1" Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Aug 18, 2014 at 2:13 AM,

[R] GSUB function and regex problem

2014-08-18 Thread Omar André Gonzáles Díaz
Hi all, i have this data.frame with 3 columns: "campaña", "visitas", "compras". This is the actual data.frame: Campaña Visitas Compras 1 facebook-Ads1 524 2 2 faceBOOK-Ads1 487 24 3 fcebook-ads12258 4 4

Re: [R] gsub question

2013-09-12 Thread arun
Hi, Try:  string1<- "Red, Romeo, Calf"  string2<- "Red, Rome, Ralf"  string3<- "China, Japan, USA"  gsub("R[[:alpha:]]{1,}","MM",string3) #[1] "China, Japan, USA" gsub("R[[:alpha:]]{1,}","MM",string2) #[1] "MM, MM, MM"  gsub("R[[:alpha:]]{1,}","MM",string1) #[1] "MM, MM, Calf" Other way would be:

Re: [R] gsub regex simplification

2013-05-08 Thread Gabor Grothendieck
On Wed, May 8, 2013 at 5:08 AM, Thaler,Thorn,LAUSANNE,Applied Mathematics wrote: > Dear all, > > I want to use gsub to change a vector of strings. Basically, I want to > replace any dot by a space, remove the possibly appended ".f" and I want to > capitalize each word. I did that by chaining mul

[R] gsub regex simplification

2013-05-08 Thread Thaler,Thorn,LAUSANNE,Applied Mathematics
Dear all, I want to use gsub to change a vector of strings. Basically, I want to replace any dot by a space, remove the possibly appended ".f" and I want to capitalize each word. I did that by chaining multiple gsubs together, but I was wondering (for the sake of learning - maybe the current ve

Re: [R] gsub -> replace substring in column

2012-08-22 Thread PIKAL Petr
Hi One more comment > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of David Winsemius > Sent: Thursday, August 23, 2012 2:22 AM > To: Paula Cafeld > Cc: r-help@r-project.org > Subject: Re: [R] gsub -&

Re: [R] gsub -> replace substring in column

2012-08-22 Thread David Winsemius
On Aug 22, 2012, at 10:24 AM, Paula Cafeld wrote: Hi all, please excuse- I'm a complete newbie to R, so it's possible my question was asked a thousand times before, but I don't get it :-( I imported a CSV file via: x=read.csv("test.csv",header=TRUE,sep="\t") In a column there are values w

Re: [R] gsub -> replace substring in column

2012-08-22 Thread arun
r-help@r-project.org" Cc: Sent: Wednesday, August 22, 2012 1:24 PM Subject: [R] gsub -> replace substring in column Hi all, please excuse- I'm a complete newbie to R, so it's possible my question was asked a thousand times before, but I don't get it :-( I imported a CSV

Re: [R] gsub -> replace substring in column

2012-08-22 Thread MacQueen, Don
This is untested, but I suspect you should try x[[9]] instead of x[9] If you want to replace the original values with the modified values, then you will need something like, x[[9]] <- gsub(".",",",x[[9]],fixed=T) The difference between single brackets [] and double brackets [[]] is importa

Re: [R] gsub -> replace substring in column

2012-08-22 Thread Rui Barradas
Hello, Your earch pattern is wrong, it should be gsub("\\.", ", ", x[9]) I find x[9] a bit strange, by the way. Specially if the column vector name is V16. Anyway, try the instruction above and if it doesn't work, post a data example with dput( head(x, 16) ) # paste the output of this in

[R] gsub -> replace substring in column

2012-08-22 Thread Paula Cafeld
Hi all, please excuse- I'm a complete newbie to R, so it's possible my question was asked a thousand times before, but I don't get it :-( I imported a CSV file via: x=read.csv("test.csv",header=TRUE,sep="\t") In a column there are values with the dot-character (".") I want to replace with a co

Re: [R] gsub

2012-06-14 Thread arun
Hi, Try this: sub("(I)\\((.*?)\\)","\\2",t1) [1] "(Ithis) test" A.K. - Original Message - From: nalluri pratap To: r-help@r-project.org Cc: Sent: Thursday, June 14, 2012 7:03 AM Subject: [R] gsub Hi,   I have a string t1="(Ithis) I(test)"

Re: [R] gsub

2012-06-14 Thread Rui Barradas
Hello, Try t1 <- "(Ithis) I(test)" t2 <- "(Ithis) test" t3 <- sub("I\\((.+)\\)", "\\1", t1) t2 == t3 #[1] TRUE If there are more than one occurences, use 'gsub'. Hope this helps, Rui Barradas Em 14-06-2012 12:03, nalluri pratap escreveu: Hi, I have a string t1="(Ithis) I(test)". I need

Re: [R] gsub

2012-06-14 Thread Sarah Goslee
> sub("I\\((.*?)\\)", "\\1", t1) # nongreedy [1] "(Ithis) test" On Thu, Jun 14, 2012 at 7:03 AM, nalluri pratap wrote: > > Hi, > > I have a string t1="(Ithis) I(test)". I need to get t2="(Ithis) test". > > Can someone look into this. ?I have tried using gsub("I[^)]","",t1) , but > didn't get th

Re: [R] gsub

2012-06-14 Thread peter dalgaard
On Jun 14, 2012, at 13:03 , nalluri pratap wrote: > > Hi, > > I have a string t1="(Ithis) I(test)". I need to get t2="(Ithis) test". > > Can someone look into this. ? Well, you can, it is your problem You need to look into the hairier parts of regular expression syntax. Looks like th

[R] gsub

2012-06-14 Thread nalluri pratap
Hi,   I have a string t1="(Ithis) I(test)". I need to get t2="(Ithis) test".   Can someone look into this. ?I have tried using gsub("I[^)]","",t1) , but didn't get the required result.   Thanks, Pratap [[alternative HTML version deleted]] __ R-

Re: [R] gsub/strsplit with multiple patterns/splits

2012-05-31 Thread mdvaan
Thank you very much. This definitely helps me out. Math Jeff Newmiller wrote > > There are many resources for learning regular expressions (e.g. > http://gnosis.cx/publish/programming/regular_expressions.html). Once you > understand the basics you will probably be able to refer to the ?regex >

Re: [R] gsub/strsplit with multiple patterns/splits

2012-05-30 Thread Fabrice Tourre
0 and 1 means zero or 1 match. Want to remove the word "Energy"? gsub("( Energy){0,1},{0,1} Inc[.]{0,1}", "", DF) On Thu, May 31, 2012 at 11:45 AM, mdvaan wrote: > Thanks! That works like a charm, but I am not sure if I fully understand the > syntax. I looked at the gsub page but still couldn't

Re: [R] gsub/strsplit with multiple patterns/splits

2012-05-30 Thread Jeff Newmiller
There are many resources for learning regular expressions (e.g. http://gnosis.cx/publish/programming/regular_expressions.html). Once you understand the basics you will probably be able to refer to the ?regex help page for specific tools. After you have waded through a tutorial, the following ex

Re: [R] gsub/strsplit with multiple patterns/splits

2012-05-30 Thread mdvaan
Thanks! That works like a charm, but I am not sure if I fully understand the syntax. I looked at the gsub page but still couldn't figure it out. What does the pattern part (",{0,1} Inc[.]{0,1}") do? What do the 0 and 1 within the curly brackets refer to? Also, what if, for example, I would want to

Re: [R] gsub/strsplit with multiple patterns/splits

2012-05-30 Thread jim holtman
Try this where you qualify how many characters you might match: > gsub(",{0,1} Inc[.]{0,1}", "", DF) [1] "Aetna""Alexander's" "Allegheny Energy" On Wed, May 30, 2012 at 6:05 PM, mdvaan wrote: > Hi, > > I have a vector like this: > > DF <- c("Aetna, Inc.", "Alexander's Inc.", "A

[R] gsub/strsplit with multiple patterns/splits

2012-05-30 Thread mdvaan
Hi, I have a vector like this: DF <- c("Aetna, Inc.", "Alexander's Inc.", "Allegheny Energy, Inc") For each element in the vector I would like to remove the "incorporated" info, so that my vector looks like this: DF <- c("Aetna", "Alexander's", "Allegheny Energy") That means that I have to str

Re: [R] gsub: replacing double backslashes with single backslash

2012-03-08 Thread Ista Zahn
rg [mailto:r-help-boun...@r-project.org] >> On Behalf Of Ista Zahn >> Sent: Wednesday, March 07, 2012 6:55 PM >> To: Greg Snow >> Cc: r-help@r-project.org; Markus Elze >> Subject: Re: [R] gsub: replacing double backslashes with single backslash >> >> On Wed

Re: [R] gsub: replacing double backslashes with single backslash

2012-03-07 Thread Daniel Nordlund
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf Of Ista Zahn > Sent: Wednesday, March 07, 2012 6:55 PM > To: Greg Snow > Cc: r-help@r-project.org; Markus Elze > Subject: Re: [R] gsub: replacing double ba

Re: [R] gsub: replacing double backslashes with single backslash

2012-03-07 Thread Jeff Newmiller
You are chasing your tail. You have already achieved your goal, but you don't seem to understand that. The three characters C:\ are represented in R as "C:\\" so when you see the latter, the former is what is actually already in memory. "C:\" is not legal R code (it is an unterminated strin

Re: [R] gsub: replacing double backslashes with single backslash

2012-03-07 Thread Ista Zahn
On Wed, Mar 7, 2012 at 12:57 PM, Greg Snow <538...@gmail.com> wrote: > > The issue here is the difference between what is contained in a string > and what R displays to you. > > The string produced with the code: > > > tmp <- "C:\\" > > only has 3 characters (as David pointed out), the third of whi

Re: [R] gsub: replacing double backslashes with single backslash

2012-03-07 Thread Greg Snow
The issue here is the difference between what is contained in a string and what R displays to you. The string produced with the code: > tmp <- "C:\\" only has 3 characters (as David pointed out), the third of which is a single backslash, since the 1st \ escapes the 2nd and the R string parsing r

Re: [R] gsub: replacing double backslashes with single backslash

2012-03-07 Thread David Winsemius
On Mar 7, 2012, at 6:54 AM, Markus Elze wrote: Hello everybody, this might be a trivial question, but I have been unable to find this using Google. I am trying to replace double backslashes with single backslashes using gsub. Actually you don't have double backslashes in the argument you

[R] gsub: replacing double backslashes with single backslash

2012-03-07 Thread Markus Elze
Hello everybody, this might be a trivial question, but I have been unable to find this using Google. I am trying to replace double backslashes with single backslashes using gsub. There seems to be some unexpected behaviour with regards to the replacement string "\\". The following example uses

Re: [R] gsub to manipulate characters

2012-02-24 Thread syrvn
cool that works! thanks a lot :) -- View this message in context: http://r.789695.n4.nabble.com/gsub-to-manipulate-characters-tp4416939p4416961.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://s

Re: [R] gsub to manipulate characters

2012-02-24 Thread Berend Hasselman
On 24-02-2012, at 12:48, syrvn wrote: > Hello, > > from a vector of strings I want to delete everything after the _ > >> v <- c("AAA_BB", "FF_MM") >> gsub("_*", "", v) > [1] "AAABB" "FFMM" > > > but should be > [1] "AAA" "FF" > > > Why does * not work? Even perl=TRUE does not give me the

[R] gsub to manipulate characters

2012-02-24 Thread syrvn
Hello, from a vector of strings I want to delete everything after the _ > v <- c("AAA_BB", "FF_MM") > gsub("_*", "", v) [1] "AAABB" "FFMM" but should be [1] "AAA" "FF" Why does * not work? Even perl=TRUE does not give me the right result Man thanks! -- View this message in context: http

Re: [R] gsub syntax help

2012-02-02 Thread Benjamin Caldwell
Oh, perfect. I was running gsub(".sample.tif", "", avec). your change gsub("\\.sample\\.tif$", "", avec) did it. Thanks Sarah *Ben Caldwell* On Thu, Feb 2, 2012 at 1:48 PM, Sarah Goslee wrote: > In the example you gave, all that has to be done is > replace ".sample.tif" at the end of the

Re: [R] gsub syntax help

2012-02-02 Thread Sarah Goslee
In the example you gave, all that has to be done is replace ".sample.tif" at the end of the string with "", which is easy. > avec <- c("SPI1.S1.str1.P3.sample.tif", "SPI1.S1.STR2.P1.sample.tif") > gsub("\\.sample\\.tif$", "", avec) [1] "SPI1.S1.str1.P3" "SPI1.S1.STR2.P1" If your real data are mo

[R] gsub syntax help

2012-02-02 Thread Benjamin Caldwell
I have some elements in a vector with extraneous information (e.g. file name and sample IDs) that I'd like to strip from every element. For example, I would like "SPI1.S1.str1.P3.sample.tif" "SPI1.S1.STR2.P1.sample.tif" to read "SPI1.S1.str1.P3" "SPI1.S1.STR2.P1". Will someone help me with the

Re: [R] gsub semicolon with double quotation mark

2012-01-25 Thread Assa Yeroslaviz
Hi Ista, sorry I didn't explain it better. What I wan to do is to change each of these line into a character vector, so that I can work with it in biomaRt. What I am principally trying to do is extract the FBgn IDs for each of these FBpp IDs. For that I need each line to be a character vector in

Re: [R] gsub semicolon with double quotation mark

2012-01-24 Thread Ista Zahn
Hi Assa, I think you should back up and tell us what you're trying to accomplish. You can replace characters in the column just as you do in a vector. But I think that is not what you're trying to do. Are you trying to split the column into three different columns? If so you can look at the colspl

Re: [R] gsub semicolon with double quotation mark

2012-01-24 Thread Assa Yeroslaviz
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 45FBpp0070037 46FBpp0070039;FBpp0070040 47FBpp0070041;FBpp0070042;FBpp0070043 48FBpp0070044;FBpp0110571 ... For one line your solution

Re: [R] gsub semicolon with double quotation mark

2012-01-24 Thread Ista Zahn
Hi Assa, On Tue, Jan 24, 2012 at 6:30 AM, Assa Yeroslaviz 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","FBp

[R] gsub semicolon with double quotation mark

2012-01-24 Thread Assa Yeroslaviz
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 wo

[R] gsub help

2011-11-14 Thread Debs Majumdar
Hi,  I am working with the following list of files: [1] "study_chr1.one.phased.impute2.chunk1"   [2] "study_chr1.one.phased.impute2.chunk1_info"  [3] "study_chr1.one.phased.impute2.chunk1_info_by_sample" [4] "study_chr1.one.phased.impute2.chunk1_summary"   [5] "study_ch

Re: [R] gsub help

2011-11-14 Thread Sarah Goslee
Hi, On Mon, Nov 14, 2011 at 7:59 PM, Debs Majumdar wrote: > Hi, > >  I am working with the following list of files: > > [1] "study_chr1.one.phased.impute2.chunk1" > [2] "study_chr1.one.phased.impute2.chunk1_info" > [3] "study_chr1.one.phased.impute2.chunk1_info_by_sample" > [4] "study_chr1.one.ph

Re: [R] gsub for numeric characters in string

2011-08-19 Thread Peter Langfelder
On Fri, Aug 19, 2011 at 11:11 AM, Rebecca Gray wrote: > Dear all, > > I have what is a bit of a confusing question, so I hope that I can explain > clearly. Thank you for your help in advance. > > I would like to do a replacement procedure on several strings, but the way > that I am currently going

[R] gsub for numeric characters in string

2011-08-19 Thread Rebecca Gray
Dear all, I have what is a bit of a confusing question, so I hope that I can explain clearly. Thank you for your help in advance. I would like to do a replacement procedure on several strings, but the way that I am currently going about it is not working. I have defined "len", which is a series

Re: [R] gsub wildcard

2011-08-15 Thread Rebecca Gray
Hi Peter, Well the problem is that I need to also move the ":" to the front of the bracketed expression, although I like the simplicity of your statement. I cannot replace all of the "[" with ":[" because I am actually just using a small example from a large file, and there are many more "[" that

Re: [R] gsub wildcard

2011-08-15 Thread Peter Langfelder
On Mon, Aug 15, 2011 at 10:34 AM, Rebecca Gray wrote: > Hello all, > > I have what I think is a simple question but I've been unable to solve it. I > have the following string: > > A[&states=1]:[&rate=2]425, B[&states=3]:[&rate=5]500 > > I would like to combine the two expressions in the [], so th

[R] gsub wildcard

2011-08-15 Thread Rebecca Gray
Hello all, I have what I think is a simple question but I've been unable to solve it. I have the following string: A[&states=1]:[&rate=2]425, B[&states=3]:[&rate=5]500 I would like to combine the two expressions in the [], so that only one set of [] is present after each letter, so that I have t

Re: [R] gsub() with unicode and escape character

2011-07-17 Thread Sverre Stausland
Sorry for not including those details. Here is a more detailed description: > data.frame(animals=c("dog","wolf","cat"))->my.data > gsub("o","\u0254",my.data$animals)->my.data$animals > my.data$animals [1] "dɔg" "wɔlf" "cat" > sessionInfo() R version 2.13.1 (2011-07-08) Platform: i386-pc-mingw3

Re: [R] gsub() with unicode and escape character

2011-07-17 Thread Uwe Ligges
t;\\numeric=<<12>>" "alpha=<>\\numeric=<<34>>" > cat(.Last.value, sep="\n") # see what is really in the strings alpha=<>\numeric=<<12>> alpha=<>\numeric=<<34>> I don't know about your unicode/encodi

Re: [R] gsub() with unicode and escape character

2011-07-17 Thread Nipesh Bajaj
;"   "alpha=<>\\numeric=<<34>>" >  > cat(.Last.value, sep="\n") # see what is really in the strings >  alpha=<>\numeric=<<12>> >  alpha=<>\numeric=<<34>> > > I don't know about your unicode/encodin

Re: [R] gsub() with unicode and escape character

2011-07-16 Thread Prof Brian Ripley
You forgot the 'at a minimum' information required by the posting guide. Most likely this is a limitation of the locale you used (and failed to tell us about) on the OS you used (...). On Sat, 16 Jul 2011, Sverre Stausland wrote: Dear helpers, I'm trying to replace a character with a unico

Re: [R] gsub() with unicode and escape character

2011-07-16 Thread Peter Langfelder
Don't know the answer to you first question, but for the \\ see below. On Sat, Jul 16, 2011 at 7:19 PM, Sverre Stausland wrote: > Unrelated to that problem, but related to gsub() is that I can't find > a way for gsub() to interpret the backslash as a character. In regular > expression, \\ should

Re: [R] gsub() with unicode and escape character

2011-07-16 Thread William Dunlap
what is really in the strings alpha=<>\numeric=<<12>> alpha=<>\numeric=<<34>> I don't know about your unicode/encoding problem. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-proj

[R] gsub() with unicode and escape character

2011-07-16 Thread Sverre Stausland
Dear helpers, I'm trying to replace a character with a unicode code inside a data frame using gsub(), but unsuccessfully. > data.frame(animals=c("dog","wolf","cat"))->my.data > gsub("o","\u0254",my.data$animals)->my.data$animals > my.data$animals [1] "dɔg" "wɔlf" "cat" It's not that a data fr

Re: [R] gsub() issue...

2011-05-17 Thread Andrew Robinson
Hi Charles, It's not clear to me what you mean by "doesn't work". > test <- "Interesting 1\nPoint\n" > cat(test) Interesting 1 Point > test1 <- gsub("ing 1\nP","ing 3\nP", test) > cat(test1) Interesting 3 Point > Cheers Andrew On Tue, May 17, 2011 at 10:45:31AM +0200, Thibault Charles wrote:

Re: [R] gsub() issue...

2011-05-17 Thread David Winsemius
The backslashes in the patt argument need to be doubled since "\" is a special regex character. Or it may work to set fixed =TRUE. Either: original <- "INFILTRATION INF_BASE \\n AIRCHANGE=1" replace <- "INFILTRATION INF_BASE \n AIRCHANGE=3" new_texte <- gsub(patt=original,replace,text) Or:

Re: [R] gsub() issue...

2011-05-17 Thread Thibault Charles
ibb Envoyé : mardi 17 mai 2011 11:15 À : r-help@r-project.org Objet : Re: [R] gsub() issue... Hello Thibault Charles, > I have the following text : > text <- ‘’ INFILTRATION INF_BASE > > AIRCHANGE=1 ‘’ becomes: text <- "INFILTRATION INF_BASE\nAIRCHANGE=1" > original

Re: [R] gsub() issue...

2011-05-17 Thread Sebastian Gibb
Hello Thibault Charles, > I have the following text : > text <- ‘’ INFILTRATION INF_BASE > > AIRCHANGE=1 ‘’ becomes: text <- "INFILTRATION INF_BASE\nAIRCHANGE=1" > original <- "INFILTRATION INF_BASE \n AIRCHANGE=1" There are spaces around "\n". That's why text != original Try original <- "INFI

[R] gsub() issue...

2011-05-17 Thread Thibault Charles
Hello R helpers, I get a problem using gsub() function. I have the following text : text <- ‘’ INFILTRATION INF_BASE AIRCHANGE=1 ‘’ Then my code is : original <- "INFILTRATION INF_BASE \n AIRCHANGE=1" replace <- "INFILTRATION INF_BASE \n AIRCHANGE=3" new_texte <- gsub

Re: [R] gsub

2010-08-06 Thread Marc Schwartz
On Aug 6, 2010, at 10:14 AM, Alfredo Alessandrini wrote: > > Hi, > > I'm using gsub, but I've a problem. > >> print(i) > [1] "piante_venere.csv" >> gsub("\\.csv$", "", i) > [1] "piante_venere" >> gsub("^piante_", "", i) > [1] "venere.csv" > > > Can I combine the two expressions? > > Like th

[R] gsub

2010-08-06 Thread Alfredo Alessandrini
Hi, I'm using gsub, but I've a problem. > print(i) [1] "piante_venere.csv" > gsub("\\.csv$", "", i) [1] "piante_venere" > gsub("^piante_", "", i) [1] "venere.csv" Can I combine the two expressions? Like this: > gsub(.) [1] "venere" Thanks, Alfredo -- View this message in context: ht

Re: [R] gsub

2010-08-06 Thread Wu Gong
i <- "piante_venere.csv" gsub("^.*_(.*)\\.csv$", "\\1", i) - A R learner. -- View this message in context: http://r.789695.n4.nabble.com/gsub-tp2316443p2316550.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org

Re: [R] gsub issue in R 2.11.1, but not present in 2.9.2

2010-06-29 Thread Uwe Ligges
t.org] On Behalf Of Uwe Ligges Sent: Tuesday, June 29, 2010 4:11 AM To: Jason Rupert Cc: r-help@r-project.org Subject: Re: [R] gsub issue in R 2.11.1, but not present in 2.9.2 On 29.06.2010 12:47, Jason Rupert wrote: Previously in R 2.9.2 I used the following to convert from an improperly formatte

Re: [R] gsub issue in R 2.11.1, but not present in 2.9.2

2010-06-29 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Bert Gunter > Sent: Tuesday, June 29, 2010 11:08 AM > To: 'Jason Rupert'; 'Duncan Murdoch' > Cc: r-help@r-project.org > Subject: Re: [R

Re: [R] gsub issue in R 2.11.1, but not present in 2.9.2

2010-06-29 Thread Bert Gunter
ice to double backslashes should be heeded as much as possible. Unfortunately, I don't think it's always possible: > newlineString <- "first line\nsecond line\n" > print(newlineString) [1] "first line\nsecond line\n" > cat(newlineString) first line second

Re: [R] gsub issue in R 2.11.1, but not present in 2.9.2

2010-06-29 Thread Bert Gunter
ecause there is already sufficient confusion that the typo may totally bewilder people. -- Bert Bert Gunter Genentech Nonclinical Statistics > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf Of Uwe Ligges > Sent: Tue

Re: [R] gsub issue in R 2.11.1, but not present in 2.9.2

2010-06-29 Thread Uwe Ligges
On 29.06.2010 12:47, Jason Rupert wrote: Previously in R 2.9.2 I used the following to convert from an improperly formatted NA string into one that is a bit more consistent. gsub("N\A", "NA", "N\A", fixed=TRUE) This worked in R 2.9.2, but now in R 2.11.1 it doesn't seem to work an throws t

Re: [R] gsub issue in R 2.11.1, but not present in 2.9.2

2010-06-29 Thread Duncan Murdoch
On 29/06/2010 6:47 AM, Jason Rupert wrote: Previously in R 2.9.2 I used the following to convert from an improperly formatted NA string into one that is a bit more consistent. gsub("N\A", "NA", "N\A", fixed=TRUE) This worked in R 2.9.2, but now in R 2.11.1 it doesn't seem to work an throws

[R] gsub issue in R 2.11.1, but not present in 2.9.2

2010-06-29 Thread Jason Rupert
Previously in R 2.9.2 I used the following to convert from an improperly formatted NA string into one that is a bit more consistent. gsub("N\A", "NA", "N\A", fixed=TRUE) This worked in R 2.9.2, but now in R 2.11.1 it doesn't seem to work an throws the following error. Error: '\A' is an unr

Re: [R] gsub with regular expression

2010-06-25 Thread Gabor Grothendieck
On Fri, Jun 25, 2010 at 11:11 AM, Gabor Grothendieck wrote: > On Fri, Jun 25, 2010 at 10:48 AM, Sebastian Kruk > wrote: >> If I have a text with 7 words per line and I would like to put first >> and second word joined in a vector and the rest of words one per >> column in a matrix how can I do it

Re: [R] gsub with regular expression

2010-06-25 Thread Allan Engelhardt
help("strsplit") is your friend, for example: t <- c("2008/12/31 12:23:31 numero 343.233.233 Rodeo Vaca Ruido", "2010/02/01 02:35:31 palabra 111.111.222 abejorro Rodeo Vaca") m <- do.call(rbind, strsplit(t, "[[:space:]]+")) # Matrix of all the data v <- paste(m[, 1], m[, 2]) # The vect

Re: [R] gsub with regular expression

2010-06-25 Thread Gabor Grothendieck
On Fri, Jun 25, 2010 at 10:48 AM, Sebastian Kruk wrote: > If I have a text with 7 words per line and I would like to put first > and second word joined in a vector and the rest of words one per > column in a matrix how can I do it? > > First 2 lines of my text file: > "2008/12/31 12:23:31 numero 3

[R] gsub with regular expression

2010-06-25 Thread Sebastian Kruk
If I have a text with 7 words per line and I would like to put first and second word joined in a vector and the rest of words one per column in a matrix how can I do it? First 2 lines of my text file: "2008/12/31 12:23:31 numero 343.233.233 Rodeo Vaca Ruido" "2010/02/01 02:35:31 palabra 111.111.22

Re: [R] gsub,regex and replacing

2010-04-28 Thread David Winsemius
ast on my client) posting. -- David. From: jim holtman [mailto:jholt...@gmail.com] Sent: Wednesday, April 28, 2010 1:31 PM To: arnaud Gaboury Cc: r-help@r-project.org Subject: Re: [R] gsub,regex and replacing Next time you include a data frame that has spaces in the fields, please consider

Re: [R] gsub,regex and replacing

2010-04-28 Thread arnaud Gaboury
, -1082, 11084, 1983.5, -2464, -118), quantity = c(0, -3, 8, 2, -1, 0)), .Names = c("DESCRIPTION", "prix", "quantity"), row.names = c(NA, -6L), class = "data.frame") From: jim holtman [mailto:jholt...@gmail.com] Sent: Wednesday, April 28, 2010 1:31

Re: [R] gsub,regex and replacing

2010-04-28 Thread jim holtman
Next time you include a data frame that has spaces in the fields, please consider using 'dput' to provided the data. It is hard to read in otherwise. Will this do it: > x <- read.table(textConnection(" DESCRIPTIONprix quantity + 1 'CORN Jul/10'-1.5

[R] gsub,regex and replacing

2010-04-28 Thread arnaud Gaboury
Dear group, I need to modify some characters in a data frame. I want to use gsub and the regex functionalities to do this. Here is the data frame (df): DESCRIPTIONprix quantity 1 CORN Jul/10-1.50 2 CORN May/10 -1082.0

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

2010-02-22 Thread Bert Gunter
riginal Message- From: r-help-boun...@r-project.org [mailto:r-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

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, functio

  1   2   >