[R] Selecting names with regard to visit frequency

arun smartpink111 at yahoo.com
Tue Jul 23 00:07:23 CEST 2013


Hi,
myvector<- c(3,2,7,4,1)
names(myvector)<-paste0("name",1:5)
names(myvector)[myvector>=3 & myvector<=5] 
#[1] "name1" "name4"
#or
names(myvector)[myvector%in% 3:5]
#[1] "name1" "name4"

#or

 names(myvector)[!is.na(match(myvector,3:5))]
#[1] "name1" "name4"



A.K.


Hello all, 
I am new to R but trying to learn. 

I have a vector of names with visit frequencies (myvector) in the form 

name1 name2 name3 name4 name5 
3              2            7            4            1 

I can select names of patients that have visited more often: 

frequent.pats<-names(myvector) [myvector>5] 

or those that have visited less often, but how could I get the names of those who visited, say between 3&5 times? 
Thanks 
steele



More information about the R-help mailing list