0

I have a table in R like below:

   [NumData]  [CharData]     
[1] 9              d
[2] 7              b
[3] 0              r
[4] 8              m
[5] 6              v

I want to have a subset of my table. This subset must be start from "7" to "8" in "NumData" column. I mean i want this subset:

[2] 7              b
[3] 0              r
[4] 8              m

I think it can be possible using subset() function in R. How can i do this? Thanks

smci
  • 32,567
  • 20
  • 113
  • 146
  • Does *"This subset must start from "7" to "8" in "Number" column"* mean only values 7 and 8, or any value with a leading digit '7' or '8', e.g. 70, 79, 82..? – smci Jan 15 '17 at 08:47
  • Also, please use `dput()` to create a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – smci Jan 15 '17 at 08:49

1 Answers1

1

We can try which to get the index

df[which(df$NumData == 7) : which(df$NumData == 8), ]

#    NumData CharData
#2       7        b
#3       0        r
#4       8        m
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213