[R] Selecting names with regard to visit frequency
arun
smartpink111 at yahoo.com
Tue Jul 23 20:29:29 CEST 2013
Hi Michael,
It is not clear how you read the dataset. It looks like a dataframe.
df1<- read.table(text='
"","x"
"A1",2
"A2",5
"A3",4
"A4",6
"A5",24
"A6",7
"A7",12
"A8",3
"A9",5
',sep=",",header=TRUE,row.names=1)
vec1<-unlist(df1)
names(vec1)<- row.names(df1)
names(vec1)[vec1%in% 3:5]
#[1] "A2" "A3" "A8" "A9"
names(vec1)[!is.na(match(vec1,3:5))]
#[1] "A2" "A3" "A8" "A9"
names(vec1)[vec1>=3 & vec1<=5]
#[1] "A2" "A3" "A8" "A9"
A.K.
________________________________
From: michael steele <real.steele500 at gmail.com>
To: smartpink111 at yahoo.com
Sent: Tuesday, July 23, 2013 11:30 AM
Subject: Re: Selecting names with regard to visit frequency
Hi A.K.,
Sorry for the confusion. The first option worked. I can't give out the actual data. But I can give something similar to its structure. Output from write.csv(myvector,file="copy") is attached.
A1, A2... represent unique identification codes for individuals. Basically, we are interested in finding individuals who have visited within a certain range. It was easy enough to find those that visited the most and the least, but not somewhere in the middle. Your first option worked and I had tried something similar (I don't remember exactly what) but I must have missed something simple.
Thanks
steele
From: <smartpink111 at yahoo.com>
>Date: Mon, Jul 22, 2013 at 11:05 PM
>Subject: Re: Selecting names with regard to visit frequency
>
>
>
>HI Steele,
>Could you provide a reproducible example for Options 2 and 3 that returns character(0)? Better would be use ?dput(). Not sure I understand you correctly. Did you meant that none of the options worked or except option 1? Also, comment regarding the practicality is also not clear.
>Tx.
><quote author='m.steele'>
>Thanks A.K., I actually tried something similar to option 1, but I missed
>something simple it seems. Options 2 and 3 do not work; they return:
>character(0)
>It may make a difference that myvector already exists, it displays in the
>form I provided. Recreating that vector in your solution may not be
>practical in this way as there are pushing towards 1000 names with
>corresponding visits.
>
>Thanks again this has been very helpful and I look forward to learning more.
>steele
></quote>
>Quoted from:
>http://r.789695.n4.nabble.com/Selecting-names-with-regard-to-visit-frequency-tp4672074p4672087.html
>
>
>_____________________________________
>Sent from http://r.789695.n4.nabble.com
>
>
>
More information about the R-help
mailing list