 Apr 13, 2018 1,342 views

## 1 answer to this question.

Yes, we can find the index of an element in a vector as follows:
> a <- c(3, 2, -7, -3, 5, 2)
> b <- (a==-7)  # this will output a TRUE/FALSE vector
> c <- which(a==-7) # this will give you numerical value
> a
  3  2 -7 -3  5  2
> b
 FALSE FALSE  TRUE FALSE FALSE FALSE
> c
 3

This is one of the most efficient methods of finding the index of an element in a vector. answered Apr 13, 2018 by
• 3,710 points

## How to write a custom function which will replace all the missing values in a vector with the mean of values in R?

Consider this vector: a<-c(1,2,3,NA,4,5,NA,NA) Write the function to impute ...READ MORE

+1 vote

## Custom Function to replace missing values in a vector with the mean of values

Try this. lapply(a,function(x){ifelse(is.na(x),mean(a,na.rm = TRUE) ...READ MORE

## Slicing a list using an index vector in r

Use index within [] and provide an ...READ MORE

## How do I remove an element from a list by index in R?

Use list[index] = NULL The list value will ...READ MORE

## How to count the number of elements with the values in a vector?

Use dplyr function group_by(). > n = as.data.frame(num) > ...READ MORE

## What is the difference between [] and [[]] notations to access the elements of a list or dataframe in R?

R provides 3 basic indexing operators. Refer ...READ MORE

## How can I control the size of points in an R scatterplot?

plot(variable, type='o' , pch=5, cex=.3) The pch argument ...READ MORE

## Locating row index of a column which has the maximum value - R

Hi, Nirvana You can also try this. which(iris\$Sepal.Length == ...READ MORE