Combin[, User_Count := .N, by = User_ID]


#1

can any pls convert this line into
combin$Usercount <-…


#2

Hello Narayana,

Why you want to convert the compact syntax of data.table ? You can do the same in a single line of code using dplyr.

combin %>% group_by(User_ID) %>% summarise(User_Count=n()) %>% merge(combin)

If you insist using base R you can use the aggregate function to create the “User_Count” variable and then merge it with the original data set

User_Count <- aggregate(cbind(N = User_ID) ~ User_ID, data = combin, FUN = function(x){NROW(x)})
merge(combin,User_Count)

hope this helps