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

2009-03-14 Thread Wacek Kusnierczyk
", > ",,,apple,,orange,lemon,strawberry")) > > It may not be the best solution, but it was my first thought > > Tom > > - Original Message ----- From: "Daren Tan" > To: > Sent: Saturday, March 14, 2009 6:42 PM > Subject: [R] gsub an

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" To: Sent: Saturday, Marc

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 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, if possible. > >

[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] "a