【发布时间】:2020-09-30 03:45:03
【问题描述】:
我有一组数据,其中受访者每个月可以回答多次。
structure(list(Month = c("Jan 2016", "Jan 2016", "Feb 2016",
"Feb 2016", "Mar 2016", "Apr 2016", "May 2016", "Jun 2016", "Jun 2016",
"Jul 2016", "Aug 2016", "Aug 2016", "Sep 2016", "Sep 2016", "Oct 2016",
"Nov 2016", "Dec 2016", "Dec 2016", "Jan 2016", "Feb 2016", "Feb 2016",
"Feb 2016", "Mar 2016", "Mar 2016", "Apr 2016", "May 2016", "May 2016",
"Jun 2016", "Jun 2016", "Jul 2016", "Aug 2016", "Aug 2016", "Oct 2016",
"Oct 2016", "Dec 2016", "Mar 2016", "Mar 2016", "Apr 2016", "Apr 2016",
"May 2016", "Jun 2016", "Aug 2016", "Sep 2016", "Jan 2016", "Jan 2016",
"Feb 2016", "Feb 2016", "Feb 2016", "Feb 2016", "Feb 2016"),
PhysicianID = c(4263, 4263, 4263, 4263, 4263, 4263, 4263,
4263, 4263, 4263, 4263, 4263, 4263, 4263, 4263, 4263, 4263,
4263, 4278, 4278, 4278, 4278, 4278, 4278, 4278, 4278, 4278,
4278, 4278, 4278, 4278, 4278, 4278, 4278, 4278, 4282, 4282,
4282, 4282, 4282, 4282, 4282, 4282, 4309, 4309, 4309, 4309,
4309, 4309, 4309)), row.names = c(NA, -50L), class = c("tbl_df",
"tbl", "data.frame"))
并且我需要知道滚动 3 个月期间的唯一受访者数量。每个月得到结果都不是问题:
sqldf("SELECT Month,COUNT(distinct(PhysicianID)) FROM Data_for_R GROUP BY Month")
Month COUNT(distinct(PhysicianID))
1 Apr 2016 3
2 Aug 2016 3
3 Dec 2016 2
4 Feb 2016 3
5 Jan 2016 3
6 Jul 2016 2
7 Jun 2016 3
8 Mar 2016 3
9 May 2016 3
10 Nov 2016 1
11 Oct 2016 2
12 Sep 2016 2
我需要的是一种返回看起来更像的结果的方法
1 Jan 2016 to March 2016 xxx
2 Feb 2016 to April 2016 xxx
3 March 2016 to May 2016 xxx
etc...
【问题讨论】:
-
问题已更新 - 道歉!
-
抱歉,第一次发帖!