R 如何从大量数据中选择在每月最后一天进行交易的会员

R 如何从大量数据中选择在每月最后一天进行交易的会员,r,dplyr,lubridate,R,Dplyr,Lubridate,我有每天进行交易的会员的数据,我需要全年每个月最后一天进行交易的所有会员的列表 我的输出需要有一个在2019年1月31日、2019年2月28日以及2019年12月31日之前交易的成员列表(包括所有列)。month.ends%过滤器(date%in%month.ends) month.ends <- as.Date(paste(unique(year(df$date)), unique(month(df$date)), "01", sep = "-"))-1 df %>% filte

我有每天进行交易的会员的数据,我需要全年每个月最后一天进行交易的所有会员的列表

我的输出需要有一个在2019年1月31日、2019年2月28日以及2019年12月31日之前交易的成员列表(包括所有列)。

month.ends%过滤器(date%in%month.ends)
month.ends <- as.Date(paste(unique(year(df$date)), unique(month(df$date)), "01", sep = "-"))-1

df %>% filter(date %in% month.ends)

如果您只想在其他一些列中使用唯一的成员名称,您可以使用distinct函数

好的,这里的代码效率很低(对于R来说相对较新),但我认为如果您只想在2019年这样做,它是有效的

#create a manual dataframe with the last days of the months in 2019
LastDays <- structure(list(Date = structure(c(7L, 2L, 10L, 4L, 11L, 5L, 
12L, 13L, 6L, 8L, 3L, 1L, 9L), .Label = c("10-12-2019", "28-2-2019", 
"30-11-2019", "30-4-2019", "30-6-2019", "30-9-2019", "31-1-2019", 
"31-10-2019", "31-12-2019", "31-3-2019", "31-5-2019", "31-7-2019", 
"31-8-2019"), class = "factor")), class = "data.frame", row.names = c(NA, 
-13L))

#remove transactions on other dates in a new dataframe
df_subset <- df[which(df$Date %in% LastDays$Date),]

#find Members which did transactions on all the last days of the month
Members <- df_subset %>% group_by(Member, Date) %>% summarise_all(funs(mean)) %>% select(Member, Date) %>% filter(n() >11)
Members <- unique(Members$Member)

#The information of all the members which transacted on all last dates of the year
df[which(df$Member %in% Members),]
#创建2019年月份最后几天的手动数据框
LastDays%选择(成员,日期)%>%筛选(n()>11)

各位成员,也许这篇文章与@maarvd相关,但不是真的,无论如何,谢谢!