-2

I have a vector of letters:

v <- c("M", "W", "M", "M", "M", "W", "M", "X", "X", "M", "X", "M", 
"M", "M", "W")

How can I have R count the letters in the vector?

Like:

M 9 
W 3
X 3
nicola
  • 24,005
  • 3
  • 35
  • 56
dolu28
  • 31
  • 2
  • 8

1 Answers1

1

You're looking for the table() function.

> table(v)
v
M W X 
9 3 3 
CDoug
  • 145
  • 6