With base R
as.data.frame(table(unique(Data)$Tid))
# Var1 Freq
# 1 1 1
# 2 2 2
# 3 3 1
# 4 4 2
Or (though the column name is less informative)
aggregate(Uid ~ Tid, unique(Data), length)
# Tid Uid
# 1 1 1
# 2 2 2
# 3 3 1
# 4 4 2
The basic idea here is to only operate on the unique combinations of Tid/Uid
and then count the different Tid
instances
Edit:
per @nicolas comment, we can add tapply
too here as a possible solution
as.data.frame.table(tapply(Data$Uid, Data$Tid, function(x) length(unique(x))))
# Var1 Freq
# 1 1 1
# 2 2 2
# 3 3 1
# 4 4 2