[R] map two names into one
arun
smartpink111 at yahoo.com
Thu Nov 8 15:32:03 CET 2012
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 <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