Hi A.K.

Thank you so much for replying this could work but the problem you recreate the 
newv1, to match v2 but I don't want to do that. I just want to check  if v2 has 
that component from v1

THanks 
Date: Thu, 1 Nov 2012 06:32:03 -0700
From: ml-node+s789695n4648123...@n4.nabble.com
To: frespi...@hotmail.com
Subject: Re: Return Vector Component



        Hi,


Not sure whether I understand it correctly.

v1 <- 
c("age_1","age_2","age_3","age_4","age_5","age_6","height_1","height_2","height_3","height_4","height_5","height_6","height_7","height_8")
 

v2 <- 
c("sex_1","sex_2","sex_3","age_height_1_1","age_height_2_2","age_height_3_3","age_height_4_4","age_height_5_5","age_height_6_6",

         "age_height_1_7","age_height_2_8") 

 v3<-gsub("(age{0,1}\\_).*","\\1",v1)

v4<-gsub("age{0,1}\\_(.*)","\\1",v1)

v5<-gsub("(height{0,1}\\_).*","\\1",v1)

v6<-gsub("height{0,1}\\_(.*)","\\1",v1)

newv1<-paste0(v3[grep("age",v3)],v5[grep("height",v5)],v4[!v4%in%v4[grep("height",v4)]],"_",v6[!v6%in%v6[grep("age",v6)]])

newv1[newv1%in%v2]

#[1] "age_height_1_1" "age_height_2_2" "age_height_3_3" "age_height_4_4"

#[5] "age_height_5_5" "age_height_6_6" "age_height_1_7" "age_height_2_8"

A.K.



        
        
        
        

        

        
        
                If you reply to this email, your message will be added to the 
discussion below:
                
http://r.789695.n4.nabble.com/Return-Vector-Component-tp4648115p4648123.html
        
        
                
                To unsubscribe from Return Vector Component, click here.

                NAML
                                                  



--
View this message in context: 
http://r.789695.n4.nabble.com/Return-Vector-Component-tp4648115p4648126.html
Sent from the R help mailing list archive at Nabble.com.
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org 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.

Reply via email to