Both the match()
(returns the first appearance) and %in%
(returns a Boolean) functions are designed for this.
v <- c('a','b','c','e')
'b' %in% v
## returns TRUE
match('b',v)
## returns the first location of 'b', in this case: 2
More Related Contents:
- R memory management / cannot allocate vector of size n Mb
- Counting the number of elements with the values of x in a vector
- How to find common elements from multiple vectors?
- Finding All Positions for Multiple Elements in a Vector
- List distinct values in a vector in R
- Convert a dataframe to a vector (by rows)
- ggplot with 2 y axes on each side and different scales
- Quickly reading very large tables as dataframes
- Counting unique / distinct values by group in a data frame
- How can I trim leading and trailing white space?
- Determine path of the executing script
- Reshape multiple value columns to wide format
- How to generate permutations or combinations of object in R?
- Numeric comparison difficulty in R
- Remove duplicated rows
- Use of ~ (tilde) in R programming Language
- Combine two or more columns in a dataframe into a new column with a new name
- Conditional merge/replacement in R
- Subset rows in a data frame based on a vector of values
- How to plot a function curve in R
- Index values from a matrix using row, col indices
- Converting two columns of a data frame to a named vector
- calculating mean for every n values from a vector
- Find start and end positions/indices of runs/consecutive values
- Display exact value of a variable in R
- Is there anything wrong with using T & F instead of TRUE & FALSE?
- Split delimited single value character vector
- R split numeric vector at position
- How to return 5 topmost values from vector in R?
- How do you create vectors with specific intervals in R?