I have data about observations across different locations and many years.
location year variable dataentry
1 1970 A 288
1 1970 A 281
1 1970 B 282
2 1970 A 282
2 1971 B 284
2 1971 B 287
I want know how many locations contributed data in each year, looking like this:
year NumberOfLocations
1970 2
1971 1
The column with "variables" and "dataentry" are not important. they only indicate that there were data entries.
I think I made it work by using group_by and summarise:
d1 <- data %>% group_by(location, year) %>% summarise(da = mean(dataentry))
d2 <- d1 %>% count(location, year)
d3 <- d2 %>% group_by(year) %>% summarise(NumberOfLocations = sum(n))
But is there a more elegant way to do it?