count equal values in a vector

# Sample vector
my_vector <- c(1, 2, 3, 2, 4, 2, 5, 6, 5, 2)

# Use table function to count occurrences of each unique value
value_counts <- table(my_vector)

# Display the counts
print(value_counts)

Explanation:

  1. my_vector <- c(1, 2, 3, 2, 4, 2, 5, 6, 5, 2): Creates a sample vector named my_vector with some numeric values.

  2. value_counts <- table(my_vector): Uses the table function to count the occurrences of each unique value in the vector. The result is stored in the variable value_counts.

  3. print(value_counts): Prints the counts of each unique value in the vector to the console.