Search code examples
rstatisticsunique

Count number of times each unique value appearing in R


I have a value arm_index which contains 46095 strings. If you do

> unique(arm_index)
 [1] "NULL"     "CMT1Y"    "TREAS6M"  "LIBOR6M"  "LIBOR1Y"  "COFI11TH"  "CMT5Y"    "TREAS1M" 
 [9] "CMT3Y"    "LIBOR1M"  "CMT6M"    "PRIMEWSJ"
> length(arm_index)
 [1] 46095

I want to find out how many times each unique value appearing here. Like the string "CMT1Y", how many times this string appearing. I am relatively new to R and done some research but couldn't find anything useful. Any suggestion will be greatly appreciated.


Solution

  • You just have to do :

    table(arm_index)