[R] map two names into one
arun
smartpink111 at yahoo.com
Thu Nov 8 16:12:20 CET 2012
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 <metal_licaling at live.com>
To: smartpink111 at yahoo.com; "r-help at r-project.org" <r-help at r-project.org>
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
More information about the R-help
mailing list