Subsetting character by names

6 views
Skip to first unread message

Avner Kantor

unread,
Aug 7, 2016, 4:34:30 AM8/7/16
to israel-r-user-group
Suppose I have
mySillyQuestion<-c("avner", "moshe", "haim", "moti", "tal", "amit")

I want to get all the names between moshe and tal without using index.

I tried subset(mySillyQuestion, select = moshe:tal)

What is the easiet way to do it? (the hard way is to use dplyr and select() columns after reshape)

Thanks,

Avner

Michael Dorman

unread,
Aug 7, 2016, 5:41:03 AM8/7/16
to israel-r-...@googlegroups.com
Here is a way to do it with base R -

x = c("avner", "moshe", "haim", "moti", "tal", "amit")
x
[1] "avner" "moshe" "haim"  "moti"  "tal"   "amit" 
x[which(x == "moshe") : which(x == "tal")]
[1] "moshe" "haim"  "moti"  "tal"  


--
You received this message because you are subscribed to the Google Groups "Israel R User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-group+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Avner Kantor

unread,
Aug 7, 2016, 5:43:28 AM8/7/16
to israel-r-user-group
Great. Thanks.

To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-group+unsubscribe...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages