I have a data frame where each row is an observation concerning a pupil. One of the vectors in the data frame is an id for the school. I have obtained a new vector with counts for each school as follows:
tbsch <- table(dt$school)
Now I want to add the relevant count value to each row in dt
. I have done it using for()
looping through each row in dt
and making a new vector containing the relevant count and finally using cbind()
to add it to dt
, but I think this is very inefficient. Is there a smart/easy way to do that ?