Dimitri Liakhovitski
2009-Sep-23 15:37 UTC
[R] Function to check if a vector contains a given value?
Dear R'rs, is there a function that checks if a given vector contains a certain value. E.g., x<-c(1,2,3,4). How can I get a TRUE or FALSE for whether x contains a 2? -- Dimitri Liakhovitski Ninah.com Dimitri.Liakhovitski at ninah.com
Jorge Ivan Velez
2009-Sep-23 15:42 UTC
[R] Function to check if a vector contains a given value?
Hi Dimitri, See either ?any, ?"%in%", or ?intersect any(x == 2) # [1] TRUE HTH, Jorge On Wed, Sep 23, 2009 at 11:37 AM, Dimitri Liakhovitski <> wrote:> Dear R'rs, > > is there a function that checks if a given vector contains a certain value. > E.g., x<-c(1,2,3,4). > How can I get a TRUE or FALSE for whether x contains a 2? > > -- > Dimitri Liakhovitski > Ninah.com > Dimitri.Liakhovitski@ninah.com > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Henrique Dallazuanna
2009-Sep-23 17:07 UTC
[R] Function to check if a vector contains a given value?
You can try this also: is.element(2, x) On Wed, Sep 23, 2009 at 12:37 PM, Dimitri Liakhovitski <ld7631 at gmail.com> wrote:> Dear R'rs, > > is there a function that checks if a given vector contains a certain value. > E.g., x<-c(1,2,3,4). > How can I get a TRUE or FALSE for whether x contains a 2? > > -- > Dimitri Liakhovitski > Ninah.com > Dimitri.Liakhovitski at ninah.com > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Maybe Matching Threads
- replacing period with a space
- Analogue to SPSS regression commands ENTER and REMOVE in R?
- R takes long time to open
- transforming a badly organized data base into a list of data frames
- referring to a row number and to a row condition, and to columns simultaneously