Search code examples
runique

R, list of duplicates with unique location and date combination


I have a database that holds hold data of animals counted with location and date, for every unique combination of location and date 1 or more animals may have been counted. I want to find the amount of unique combinations of location and date. After this, I want to find the amount of duplications of only location (so i know how many times each location has been measured in total)

i used locations <- table(STOWA$locality) to get a list of each location and the amount of times it occured, but i first need to get a list of every unique combination of location and date and then use table() on it.

pseudocode below of what i want to achieve

newList <- (where STOWA$locality + STOWA$date = unique)
locations <- table(newList(only on location,not date))

How do i do this?


Solution

  • You can do this with simple dplyr code:

    unique_combination <- df %>% 
        count(animal, location, time)
    

    Location:

    count_location <- df %>%
            count(location)