Find Index of Element in Vector in R (2 Examples) | match & which Functions

preview_player
Показать описание
R code of this video:

x <- c(4, 1, 6, 7, 2, 1, 1) # Create example vector

match(1, x) # match function finds first element
# 2

which(x %in% 1) # which function identifies all elements
# 2 6 7
Рекомендации по теме
Комментарии
Автор

What code would you use to determine how many elements (aka how many
fruits) there are in the vector `fruits`?

azharmehmood
Автор

How will you check if an element is present in a vector?

ginomacalino
Автор

Warning message:
In merge.zoo(e1, e2, all = FALSE, retclass = NULL) :
Index vectors are of different classes: numeric integer

could u plz tell me how to solve this error

vanidacastelino
Автор

Moreover, one can replace x with the column of a data frame, I just tested it!!

agsoutas
Автор

how common Elements in both vectors to be Pasted with symbol "-"

manivikram