Grokbase Groups R r-help March 2002
FAQ
i am probably just missing this one, but how can i check to see if a number
is a part of a vector?

i know i could do a loop checking for equivalence for each element, but i am
thinking that there must be a simpler way to do it than that ( i think that
i have even done it in the past, but can't remember how!)
thanks

what i am working with:
(hope this makes sense)

arclist
[1] 2 2 6 7 8 9 9 11 11 11 12 13 14 15 16 17 19
21
[19] 22 23 24 25 25 29 29 30 32 34 35 35 38 39 40 40 41
42
[37] 43 44 45 46 47 48 49 50 51 52 53 54 57 58 59 60 61
61
[55] 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61
61
[73] 61 61 61 61 61 61 61 61 61 61 62 65 67 68 68 69 71
72
[91] 75 76 77 79 81 82 83 84 84 85 86 87 88 90 91 92 93
94
[109] 95 96 96 96 96 100

# and am sampling from a different list
# if i draw, say 80, i would then not want to proceed, but if i draw a
number on arclist i do



jimi adams
Department of Sociology
The Ohio State University
300 Bricker Hall
190 N Oval Mall
Columbus, OH 43210-1353
614-688-4261

our mind has a remarkable ability to think of contents as being independent
of the act of thinking
-georg simmel


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

Search Discussions

  • Deepayan Sarkar at Mar 20, 2002 at 5:24 pm
    You are probably looking for %in%
    (e.g., 80 %in% arclist should be FALSE,
    81 %in% arclist should be TRUE).


    --- jimi adams wrote:
    i am probably just missing this one, but how can i check to see if a number
    is a part of a vector?

    i know i could do a loop checking for equivalence for each element, but i am
    thinking that there must be a simpler way to do it than that ( i think that
    i have even done it in the past, but can't remember how!)
    thanks

    what i am working with:
    (hope this makes sense)

    arclist
    [1] 2 2 6 7 8 9 9 11 11 11 12 13 14 15 16 17 19
    21
    [19] 22 23 24 25 25 29 29 30 32 34 35 35 38 39 40 40 41
    42
    [37] 43 44 45 46 47 48 49 50 51 52 53 54 57 58 59 60 61
    61
    [55] 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61
    61
    [73] 61 61 61 61 61 61 61 61 61 61 62 65 67 68 68 69 71
    72
    [91] 75 76 77 79 81 82 83 84 84 85 86 87 88 90 91 92 93
    94
    [109] 95 96 96 96 96 100

    # and am sampling from a different list
    # if i draw, say 80, i would then not want to proceed, but if i draw a
    number on arclist i do



    jimi adams
    Department of Sociology
    The Ohio State University
    300 Bricker Hall
    190 N Oval Mall
    Columbus, OH 43210-1353
    614-688-4261

    our mind has a remarkable ability to think of contents as being independent
    of the act of thinking
    -georg simmel


    -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
    r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
    Send "info", "help", or "[un]subscribe"
    (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
    __________________________________________________



    -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
    r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
    Send "info", "help", or "[un]subscribe"
    (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
  • Jason Turner at Mar 20, 2002 at 6:40 pm

    On Wed, Mar 20, 2002 at 11:40:58AM -0500, jimi adams wrote:
    i am probably just missing this one, but how can i check to see if a number
    is a part of a vector? ...
    # if i draw, say 80, i would then not want to proceed, but if i draw a
    number on arclist i do
    if( !(80 %in% arclist)) {...}

    Getting a bit trickier, if you need to know which element it is,
    check out "which()". e.g. if you would only proceed if 79 was
    one of the first 20 elements

    if(any(which(arclist == 79) < )) {...}

    Cheers

    Jason
    --
    Indigo Industrial Controls Ltd.
    64-21-343-545
    jasont at indigoindustrial.co.nz
    -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
    r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
    Send "info", "help", or "[un]subscribe"
    (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
  • Scott, Uriel at Mar 20, 2002 at 6:45 pm
    I think the which() function would be helpful. For example if x is a vector
    and c some value then
    which( x == c )
    will return a vector of those indices i of x for which x[i] = c. Then you
    can test whether that vector
    has length 0.
    -----Original Message-----
    From: jimi adams [SMTP:imij at columbus.rr.com]
    Sent: Wednesday, March 20, 2002 11:41 AM
    To: r-help at stat.math.ethz.ch
    Subject: [R] check without loop

    i am probably just missing this one, but how can i check to see if a
    number
    is a part of a vector?

    i know i could do a loop checking for equivalence for each element, but i
    am
    thinking that there must be a simpler way to do it than that ( i think
    that
    i have even done it in the past, but can't remember how!)
    thanks

    what i am working with:
    (hope this makes sense)

    arclist
    [1] 2 2 6 7 8 9 9 11 11 11 12 13 14 15 16 17 19
    21
    [19] 22 23 24 25 25 29 29 30 32 34 35 35 38 39 40 40 41
    42
    [37] 43 44 45 46 47 48 49 50 51 52 53 54 57 58 59 60 61
    61
    [55] 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61
    61
    [73] 61 61 61 61 61 61 61 61 61 61 62 65 67 68 68 69 71
    72
    [91] 75 76 77 79 81 82 83 84 84 85 86 87 88 90 91 92 93
    94
    [109] 95 96 96 96 96 100

    # and am sampling from a different list
    # if i draw, say 80, i would then not want to proceed, but if i draw a
    number on arclist i do



    jimi adams
    Department of Sociology
    The Ohio State University
    300 Bricker Hall
    190 N Oval Mall
    Columbus, OH 43210-1353
    614-688-4261

    our mind has a remarkable ability to think of contents as being
    independent
    of the act of thinking
    -georg simmel


    -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
    -.-.-
    r-help mailing list -- Read
    http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
    Send "info", "help", or "[un]subscribe"
    (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
    _._._
    -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
    r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
    Send "info", "help", or "[un]subscribe"
    (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
  • Jimi adams at Mar 20, 2002 at 8:32 pm
    thanks to all,
    %in%
    was what i was looking for

    ----- Original Message -----
    From: "Scott, Uriel" <uriel.scott@mirant.com>
    To: "'jimi adams'" <imij@columbus.rr.com>; <r-help@stat.math.ethz.ch>
    Sent: Wednesday, March 20, 2002 1:45 PM
    Subject: RE: [R] check without loop

    I think the which() function would be helpful. For example if x is a vector
    and c some value then
    which( x == c )
    will return a vector of those indices i of x for which x[i] = c. Then you
    can test whether that vector
    has length 0.
    -----Original Message-----
    From: jimi adams [SMTP:imij at columbus.rr.com]
    Sent: Wednesday, March 20, 2002 11:41 AM
    To: r-help at stat.math.ethz.ch
    Subject: [R] check without loop

    i am probably just missing this one, but how can i check to see if a
    number
    is a part of a vector?

    i know i could do a loop checking for equivalence for each element, but
    i
    am
    thinking that there must be a simpler way to do it than that ( i think
    that
    i have even done it in the past, but can't remember how!)
    thanks

    what i am working with:
    (hope this makes sense)

    arclist
    [1] 2 2 6 7 8 9 9 11 11 11 12 13 14 15 16 17
    19
    21
    [19] 22 23 24 25 25 29 29 30 32 34 35 35 38 39 40 40
    41
    42
    [37] 43 44 45 46 47 48 49 50 51 52 53 54 57 58 59 60
    61
    61
    [55] 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61
    61
    61
    [73] 61 61 61 61 61 61 61 61 61 61 62 65 67 68 68 69
    71
    72
    [91] 75 76 77 79 81 82 83 84 84 85 86 87 88 90 91 92
    93
    94
    [109] 95 96 96 96 96 100

    # and am sampling from a different list
    # if i draw, say 80, i would then not want to proceed, but if i draw a
    number on arclist i do



    jimi adams
    Department of Sociology
    The Ohio State University
    300 Bricker Hall
    190 N Oval Mall
    Columbus, OH 43210-1353
    614-688-4261

    our mind has a remarkable ability to think of contents as being
    independent
    of the act of thinking
    -georg simmel

    -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
    -.-.-
    r-help mailing list -- Read
    http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
    Send "info", "help", or "[un]subscribe"
    (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
    _._._
    -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
    r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
    Send "info", "help", or "[un]subscribe"
    (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
    _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupr-help @
categoriesr
postedMar 20, '02 at 4:40p
activeMar 20, '02 at 8:32p
posts5
users4
websiter-project.org
irc#r

People

Translate

site design / logo © 2017 Grokbase