I have a data frame with IDs for web page ('Webpage'), department ('Dept') and employee ('Emp_ID'):
df <- data.frame(Webpage = c(111, 111, 111, 111, 222, 222),
Dept = c(101, 101, 101, 102, 102, 103),
Emp_ID = c(1, 1, 2, 3, 4, 4))
# Webpage Dept Emp_ID
# 1 111 101 1
# 2 111 101 1
# 3 111 101 2
# 4 111 102 3
# 5 222 102 4
# 6 222 103 4
I want to know how many unique individual has seen the different webpages.
For e.g. in the following dataset webpage 111 has been seen by three individual (unique combination of Dept and emp ID). So webpage 111 has been seen by emp_ID 1,2 and 3 in Dept 101 and 102. Similarly webpage 222 has been seen by two different individual.
My first attempt is:
nrow(unique(data[ , c("Dept", "Emp_ID)]))
Using unique I can do for one web page, but can someone please suggest how I can calculate this for all web pages
