R get all categories in column

user3443063 picture user3443063 · Sep 2, 2017 · Viewed 36.2k times · Source

I have a large Dataset (dataframe) where I want to find the number and the names of my cartegories in a column.

For example my df was like that:

 A   B   
 1   car
 2   car
 3   bus
 4   car
 5   plane 
 6   plane 
 7   plane 
 8   plane 
 9   plane 
 10   train

I would want to find :

  car
  bus
  plane
  train
  4

How would I do that?

Answer

CCD picture CCD · Sep 2, 2017
categories <- unique(yourDataFrame$yourColumn) 
numberOfCategories <- length(categories)

Pretty painless.