1157/how-to-count-the-number-of-elements-with-the-values-in-vector

Consider a vector of numbers:

num <- c(2,13,7,13,51,43,44,76,647,37,367,435, 443,425,314,31,416,16,367,65,44,425)

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

You have various options to count the number of times a number occurs:

One of them is to use table():

z <- table(num) > z num 2 7 13 16 31 37 43 44 51 65 76 314 367 416 425 435 443 647 1 1 2 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 1

Then you can subset it, for the number you want the count for:

z[names(z)==367] 367 2

The second option is to convert it into a data.frame

as.data.frame(table(num)) num Freq 1 2 1 2 7 1 3 13 2 4 16 1 ...

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

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

Use nrow() to find number of rows ...READ MORE

How to fit different elements in a ...READ MORE

You can try na.omit() or na.exclude() too. ...READ MORE

Basically here we are making an equation ...READ MORE

By assuming that all the values are ...READ MORE

For avoiding rowwise(), I prefer to use ...READ MORE

You can use the sapply function, to loop ...READ MORE

You can use complete.cases in the following ...READ MORE

OR