Counting the number of elements with the values of x in a vector

后端 未结 19 1366
闹比i
闹比i 2020-11-22 02:44

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 hav

19条回答
  •  一生所求
    2020-11-22 03:43

    I would probably do something like this

    length(which(numbers==x))
    

    But really, a better way is

    table(numbers)
    

提交回复
热议问题