Create frequency table in R

r
data_wrangling

#1

customer_number Discount_Name
123 Gold
345 Silver
125 Gold
234 Platinum
567 Silver

I need to create my frequency table like

Discount_Name Frequency
Gold 2
Silver 1

   Platinum             1

#2

This will help-
data.frame(table(data$Discount_Name))

Usually, these kind of questions are just a google away :slight_smile:


#3

My dataframe have
’data.frame’: 298268 obs. of 30 variables:
customer_number : num 9672150 9672150 2418031 2418031 9977307 ... county_id : num 15 15 18 18 9 18 18 18 18 18 …
$ discount_name : chr “Minipris 8” “Minipris 5” “Minipris 8” “Minipris 8” …
by this I got frequency of discount_name.

mydata.frame(table(mydata$discount_name))

Var1 Freq
1 Allibert 273
2 Arr. rabatt 2 216
3 Arr. rabatt 5 116
4 Familierabatt 8279
5 Ingen verd 136235
6 SIT 41

Based on frequency condition, replace var1 value name. like If Frequency is less than 100 put value OTHER.It means SIT should replace be OTHER.

Var1 Freq
1 Allibert 273
2 Arr. rabatt 2 216
3 Arr. rabatt 5 116
4 Familierabatt 8279
5 Ingen verd 136235
6 OTHER 41

But how merge/ modify my change in original DF (mydata).


#4

As I said this is just a google away :slight_smile:

data$Var1[data$Freq<100] <- ‘OTHER’


#5

I need to merge all discount names with less than 100 tickets into OTHER .