【发布时间】:2021-05-22 11:31:38
【问题描述】:
我有一个包含物种出现次数(TD_threshold)的data.frame。这种情况分为不同的个体和不同的月份。我的目标是选择每个月出现超过 40 次的个人。应用以下代码时,某些月份没有出现但其他月份超过 40 个的个体仍然存在。
set.seed(28)
TD_samples <-
TD_threshold %>%
as.data.frame() %>%
group_by(ind_id, month) %>%
sample_n(40)
head(TD_threshold)
# A tibble: 6 x 5
# Groups: ind_id, month [1]
time ind_id month lng lat
<dttm> <fct> <dbl> <dbl> <dbl>
1 2015-01-01 09:40:23 BAV3 1 -588886. 1373720.
2 2015-01-01 10:40:06 BAV3 1 -618226. 1372848.
3 2015-01-01 12:00:06 BAV3 1 -655789. 1353752.
4 2015-01-01 13:30:06 BAV3 1 -701669. 1349417.
5 2015-01-01 15:00:06 BAV3 1 -727293. 1335201.
6 2015-01-02 10:40:06 BAV3 1 -726753. 1334190.
【问题讨论】: