R,具有唯一位置和日期组合的重复项列表
R, list of duplicates with unique location and date combination
我有一个数据库,其中包含按位置和日期计算的动物数据,对于位置和日期的每个唯一组合,可能会计算 1 只或更多动物。我想找到位置和日期的独特组合的数量。在此之后,我想找到唯一位置的重复量(所以我知道每个位置总共测量了多少次)
我使用 locations <- table(STOWA$locality)
获取每个位置的列表及其出现的次数,但我首先需要获取位置和日期的每个唯一组合的列表,然后使用 table()
就可以了。
下面是我想要实现的伪代码
newList <- (where STOWA$locality + STOWA$date = unique)
locations <- table(newList(only on location,not date))
我该怎么做?
您可以使用简单的 dplyr 代码执行此操作:
unique_combination <- df %>%
count(animal, location, time)
地点:
count_location <- df %>%
count(location)
为什么不是这个?
library(dplyr)
newlist <- df %>% group_by(locality, date) %>% slice_head()
这将为您提供每个组合的唯一组合,基本上是第一行。
我有一个数据库,其中包含按位置和日期计算的动物数据,对于位置和日期的每个唯一组合,可能会计算 1 只或更多动物。我想找到位置和日期的独特组合的数量。在此之后,我想找到唯一位置的重复量(所以我知道每个位置总共测量了多少次)
我使用 locations <- table(STOWA$locality)
获取每个位置的列表及其出现的次数,但我首先需要获取位置和日期的每个唯一组合的列表,然后使用 table()
就可以了。
下面是我想要实现的伪代码
newList <- (where STOWA$locality + STOWA$date = unique)
locations <- table(newList(only on location,not date))
我该怎么做?
您可以使用简单的 dplyr 代码执行此操作:
unique_combination <- df %>%
count(animal, location, time)
地点:
count_location <- df %>%
count(location)
为什么不是这个?
library(dplyr)
newlist <- df %>% group_by(locality, date) %>% slice_head()
这将为您提供每个组合的唯一组合,基本上是第一行。