df <- data.frame(name=c('black','black','black','red','red'),
type=c('chair','chair','sofa','sofa','sofa'),
num=c(4,4,12,4,6))
For each row, I want to count the number of times that "type" appears with that row's num value, and then create a new column. So for the first row, "chair" and "num" appears twice in the dataset, so it gets assigned a 2. For the second row, same thing. For the 3rd row, sofa appears once with a value of 12.
df
# name type num count
# 1 black chair 4 2
# 2 black chair 4 2
# 3 black sofa 12 1
# 4 red sofa 4 1
# 5 red sofa 6 1