Re: [R] Special characters in regular expressions

2015-09-27 Thread Patrick Connolly
On Thu, 24-Sep-2015 at 12:38PM +0200, peter dalgaard wrote: |> |> On 24 Sep 2015, at 12:05 , Thierry Onkelinx wrote: |> |> > gsub("[A|K]\\|", "", x) |> |> That'll probably do it, but what was the point of the | in [A|K] ?? |> I don't think it does what I think you think it does... |> Somewha

Re: [R] Special characters in regular expressions

2015-09-24 Thread Upton, Stephen (Steve) (CIV)
To: Thierry Onkelinx Cc: R-help Subject: Re: [R] Special characters in regular expressions On 24 Sep 2015, at 12:05 , Thierry Onkelinx wrote: > gsub("[A|K]\\|", "", x) That'll probably do it, but what was the point of the | in [A|K] ?? I don't think it does what

Re: [R] Special characters in regular expressions

2015-09-24 Thread peter dalgaard
On 24 Sep 2015, at 12:05 , Thierry Onkelinx wrote: > gsub("[A|K]\\|", "", x) That'll probably do it, but what was the point of the | in [A|K] ?? I don't think it does what I think you think it does... Somewhat safer, maybe: gsub("\\|[AK]\\|","\\|", x) (avoids surprises from, say, "LBAM 5|A|

Re: [R] Special characters in regular expressions

2015-09-24 Thread Thierry Onkelinx
gsub("[A|K]\\|", "", x) ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium To call in the statistician after the experiment is done ma

[R] Special characters in regular expressions

2015-09-24 Thread Patrick Connolly
I need to change a vector dd that looks like this: c("LBAM 5|A|15C|3h", "LBAM 5|K|15C|2h") into this: c("LBAM 5|15C|3h", "LBAM 5|15C|2h") It's not very imaginative, but I could use a complicated nesting of gsub() as so: gsub("-", "\\|", gsub("K-", "", gsub("A-", "", gsub("\\|", "-", dd Or