0 votes
1 view
in R Programming by (5.8k points)

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?

1 Answer

0 votes
by (25.3k points)

You can use the table() function to print the frequency of each element present in a vector.

In your case:

>count <- table(numbers)

>count

Output:

numbers

4   5  23  34  43  54  56  65  67 324 435 453 456 567 657

2   1   2   2   1   1   2   1   2   1   3   1   1   1   1 

For a particular element, use the following code:

> count[names(count)==56]

56 

 2

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...