rcategoriesdatacolumn

R get all categories in column


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?


Solution

  • categories <- unique(yourDataFrame$yourColumn) 
    numberOfCategories <- length(categories)
    

    Pretty painless.