Mars:
ticket Name Fare
A3 Emily 50
A4 Jack 50
A5 Sam 25
A6 Lara 25
A4 Julie 50
A3 Kevin 50
When we go to the movies, sometimes we buy one ticket for two people's price. Now I need to count the repeated data. I know how to count it, but not sure how to put it back into the data frame since the length will be different.
My code:
a <- as.data.frame(table(Mars$ticket))
Mars$Count <- Mars$ticket[a$Var2]
Output:
var1 Var2
A3 2
A4 2
A5 1
A6 1
Error
replacement has 4 rows, data has 6
Expected output:
Mars:
ticket Name Fare Count
A3 Emily 50 2
A4 Jack 50 2
A5 Sam 25 1
A6 Lara 25 1
A4 Julie 50 2
A3 Kevin 50 2