HI Tammy,
Apologies!
I failed to notice the space between 16 and G in your example. Just to
understand it, how often do you find these space issues? Also, is it always
between G and which ever number before that? Do you find space issues between
S and the number before that?
If the problem is only for G, then try this:
fun1<-function(x){
res<-ifelse(grepl("\\sG",x),x,gsub("(.*)(G)","\\1 \\2",x))
res2<-paste(sort(unlist(strsplit(res," "))),collapse= "_")
res2}
vec1<-"Iphone 4S 16 G"
vec2<-"4S G 16 Iphone"
vec3<-"16 G Iphone 4S"
vec4<-"3S G 16 Iphone"
vec5<-"Iphone 4S 16G"
fun1(vec1)
#[1] "16_4S_G_Iphone"
fun1(vec2)
#[1] "16_4S_G_Iphone"
fun1(vec3)
#[1] "16_4S_G_Iphone"
fun1(vec4)
#[1] "16_3S_G_Iphone"
fun1(vec5)
#[1] "16_4S_G_Iphone"
identical(fun1(vec1),fun1(vec5))
#[1] TRUE
identical(fun1(vec1),fun1(vec4))
#[1] FALSE
A.K.
________________________________
From: Tammy Ma <[email protected]>
To: [email protected]; "[email protected]" <[email protected]>
Sent: Thursday, November 8, 2012 8:12 AM
Subject: Re: [R] map two names into one
Thanks.
Yes. Your approach can identify:
Glaxy ace S 5830 and
S 5830 Glaxy ace
But you can not identify using same program:
Iphone 4S 16 G
Iphone 4S 16G
How should I solve both in same time.
Kind regards,
Tammy
______________________________________________
[email protected] 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.