Hi,
After thinking about this for some other situations, I think this function will
be more suitable.
fun2<-function(x){
res1<-toupper(x)
res2<-
gsub("^\\s+|\\s+$","",paste0(sort(unlist(strsplit(res1,""))),collapse=""))
res2}
vec6<-"Glaxy ace S 5830"
vec7<-"S 5830 Glaxy ace"
vec1<-"Iphone 4S 16 G"
vec2<-"4S G 16 Iphone"
vec3<-"16 G Iphone 4S"
vec4<-"3S G 16 Iphone"
vec5<-"Iphone 4S 16G"
fun2(vec1)
#[1] "146EGHINOPS"
fun2(vec2)
#[1] "146EGHINOPS"
fun2(vec3)
#[1] "146EGHINOPS"
fun2(vec4)
#[1] "136EGHINOPS"
fun2(vec5)
#[1] "146EGHINOPS"
fun2(vec6)
#[1] "0358AACEGLSXY"
fun2(vec7)
#[1] "0358AACEGLSXY"
identical(fun2(vec1),fun2(vec5))
#[1] TRUE
identical(fun2(vec1),fun2(vec4))
#[1] FALSE
vec5
#[1] "Iphone 4S 16G"
identical(fun2(vec6),fun2(vec7))
#[1] TRUE
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.