[R] map two names into one

arun smartpink111 at yahoo.com
Thu Nov 8 14:27:31 CET 2012


HI,

The context was missing.  I had to dig through Nabble to find what you actually meant.

 vec1<-"Iphone 4S 16 G"
 vec2<-"4S G 16 Iphone"
 vec3<-"16 G Iphone 4S"
vec4<-"3S G 16 Iphone"

 res2<-paste(sort(unlist(strsplit(vec2," "))),collapse= " ")
 res3<-paste(sort(unlist(strsplit(vec3," "))),collapse= " ")
 res1<-paste(sort(unlist(strsplit(vec1," "))),collapse= " ")
res4<-paste(sort(unlist(strsplit(vec4," "))),collapse= " ")

 identical(res1,res2)
#[1] TRUE
 identical(res1,res3)
#[1] TRUE
identical(res1,res4)
#[1] FALSE

 res1
#[1] "16 4S G Iphone"
 res4
#[1] "16 3S G Iphone"

I think I previously used:
res33<-paste(sort(unlist(strsplit(vec3," "))),collapse= "_") #this should also work
 res44<-paste(sort(unlist(strsplit(vec4," "))),collapse= "_")
res11<-paste(sort(unlist(strsplit(vec4," "))),collapse= "_")
 identical(res11,res33)
#[1] FALSE
identical(res11,res44)
#[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