[R] map two names into one
arun
smartpink111 at yahoo.com
Thu Nov 8 15:41:20 CET 2012
HI,
A small modification of my earlier approach as it creates a problem for "Glaxy ace..."
Use:
fun1<-function(x){
res<-ifelse(grepl("\\sG",x),x,gsub("(.*)(G)","\\1 \\2",x))
res2<-paste(sort(unlist(strsplit(res," "))),collapse= "") # 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"
fun1(vec6)
#[1] "5830aceGlaxyS"
fun1(vec7)
#[1] "5830aceGlaxyS"
fun1(vec1)
#[1] "164SGIphone"
fun1(vec2)
#[1] "164SGIphone"
fun1(vec3)
#[1] "164SGIphone"
fun1(vec4)
#[1] "163SGIphone"
fun1(vec5)
#[1] "164SGIphone"
fun1(vec6)
#[1] "5830aceGlaxyS"
identical(fun1(vec6),fun1(vec7))
#[1] TRUE
identical(fun1(vec5),fun1(vec1))
#[1] TRUE
identical(fun1(vec1),fun1(vec4))
#[1] FALSE
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