I have a vector of numbers:

```numbers <- c(4,23,4,23,5,43,54,56,657,67,67,435,
453,435,324,34,456,56,567,65,34,435)
```

How can I have R count the number of times a value x appears in the vector?

Jun 14, 2022 449 views

## 1 answer to this question.

You may simply use the table() method:

> a <- table(numbers) > a \snumbers
4 5 23 34 43 54 56 65 67 324 435 453 456 567 657 324 435 453 456 567 657 324 435 453 456 567 657 324 435 4
2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Then you can subset it:

> a[names(a)==435]
435
3
Or convert it into a data.frame if you're more comfortable working with that:

> as.data.frame(table(numbers)) numbers Freq 1 4 2 2 5 1 3 23 2 4 34 2
• 3,040 points

+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

## 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

## How can I find number of rows in a dataframe, and how to find the number of rows that dont have null values

Use nrow() to find number of rows ...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

## Test if a vector contains a given element

1. Making use of the std::count function Counting ...READ MORE

## How to create excellent examples in R?

An excellent example must consist of the ...READ MORE

+1 vote

## 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

## How to remove NA values from a Vector in R?

Hello team, you can use na.omit x <- c(NA, 3, ...READ MORE