Hi I have a vector like that readCsvFile$V1 [1] 30 31 32 33 34 35 36 37 38 39 310 311 312 313 314 315 316 317 318 [20] 319 320 321 20 21 22 23 24 25 26 27 28 29 210 211 212 213 214 215 [39] 216 217 218 219 220 221 222 223 40 41 42 43 44 45 46 47 48 49 410 [58] 411 412 413 414 415 416 417 418 419 420 421 and I am looking to find where the number 31 is located. So I need one function to return me the index of where the number 31 is. Is there a function for that in R? Regards Alex [[alternative HTML version deleted]]
Hi, Alaios, check out ?which and in particular its "Examples" and "See Also" section. Hth -- Gerrit On Tue, 22 Oct 2013, Alaios wrote:> Hi I have a vector like that > > readCsvFile$V1 > ?[1]? 30? 31? 32? 33? 34? 35? 36? 37? 38? 39 310 311 312 313 314 315 316 317 318 > [20] 319 320 321? 20? 21? 22? 23? 24? 25? 26? 27? 28? 29 210 211 212 213 214 215 > [39] 216 217 218 219 220 221 222 223? 40? 41? 42? 43? 44? 45? 46? 47? 48? 49 410 > [58] 411 412 413 414 415 416 417 418 419 420 421 > > > and I am looking to find where the number 31 is located. So I need one function to return me the index of where the number 31 is. > Is there a function for that in R? > > Regards > Alex
Follow these examples:> grep(5,1:10)[1] 5> grep(3, c(1,5,2,3,6))[1] 4 -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 10/22/13 4:21 AM, "Alaios" <alaios at yahoo.com> wrote:>Hi I have a vector like that > >readCsvFile$V1 > [1] 30 31 32 33 34 35 36 37 38 39 310 311 312 313 314 315 316 >317 318 >[20] 319 320 321 20 21 22 23 24 25 26 27 28 29 210 211 212 213 >214 215 >[39] 216 217 218 219 220 221 222 223 40 41 42 43 44 45 46 47 48 >49 410 >[58] 411 412 413 414 415 416 417 418 419 420 421 > > >and I am looking to find where the number 31 is located. So I need one >function to return me the index of where the number 31 is. >Is there a function for that in R? > >Regards >Alex > [[alternative HTML version deleted]] >