Skip to content

Splitting a character vector.

6 messages · Rui Barradas, arun, John Kane

#
Oh, right!

The close parenthesis isn't doing nothing in the result, t could be done 
after but since we're to it...

Rui Barradas

Em 07-07-2012 23:10, Mark Leeds escreveu:
#
Ah, I think Mark may have it.  See my earlier post.  Why the space?

John Kane
Kingston ON Canada
____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!
#
The space is for a different reason, strsplit doesn't put the split 
pattern in the result, so if a space is included it will be 
automatically deleted. For instance in "XXY (mat harry)" without the 
space it would become "XXY " and "mat harry)" but we want "XXY" so 
include the space in the pattern.

Another example, this one artificial:

"123AB456" ---> "123" and "456"

strsplit("123AB456", "B") ---> "123A" and "456"

So include the "A" in the pattern. It's _exactly_ the same thing.

Rui Barradas

Em 07-07-2012 23:21, John Kane escreveu:
#
I think I'm geting it a bit. Anyway time to shut down and have a beer.  Life will be much nice tomorrow or Monday when I get back to cleaning up the data from that spreadsheet.  

Many thanks and have a good weekend.

John Kane
Kingston ON Canada
____________________________________________________________
GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys
Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails
#
HI John,
If I understand the post, in your original data, there is a space between XXY and (.
If there was no space,

dd1? <-? c( "XXY(mat harry)","XXY(jim bob)", "CAMP(joe blow)", "ALP(max jack)")

#Rui's original code will produce
result<-strsplit(sub(close.par,"",dd1),open.par)
[[1]]
[1] "XXY(mat harry"

[[2]]
[1] "XXY(jim bob"

[[3]]
[1] "CAMP(joe blow"

[[4]]
[1] "ALP(max jack"


#But, if I wanted to get the result as in the original data strsplit,
result<-strsplit(sub(close.par," ",dd1),open.par)
[[1]]
[1] "XXY"??????? "mat harry "

[[2]]
[1] "XXY"????? "jim bob "

[[3]]
[1] "CAMP"????? "joe blow "

[[4]]
[1] "ALP"?????? "max jack "


A.K.






----- Original Message -----
From: John Kane <jrkrideau at inbox.com>
To: Rui Barradas <ruipbarradas at sapo.pt>
Cc: r-help at r-project.org
Sent: Saturday, July 7, 2012 6:33 PM
Subject: Re: [R] Splitting a character vector.

I think I'm geting it a bit. Anyway time to shut down and have a beer.? Life will be much nice tomorrow or Monday when I get back to cleaning up the data from that spreadsheet.? 

Many thanks and have a good weekend.

John Kane
Kingston ON Canada
____________________________________________________________
GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys
Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
1 day later
#
Right, I see it now. Thanks.  

Who knows in another 100 years I may understand regex.

John Kane
Kingston ON Canada
____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!