每周制定会议-有关代码的问题

时间:2019-06-20 21:59:25

标签: r dataframe dataset frequency frequency-analysis

可以在多个月内找到个人(即Name1可能从4月到12月接受透析;因此为什么要多次列出)-每行都有一个日期,是一个疗程(我需要确定每位患者每周的疗程频率)。

这是到目前为止的代码,但仍会显示错误

UseMethod(“ group_by_”)中的错误: 没有适用于'group_by_'的适用方法应用于类“ c('integer','numeric')”的对象

HD$week_year <- paste(week(HD$date), year(HD$date), sep = "-")
filter(HD, modality == "HD") %>%
+ group_by(HD$id, HD$name, HD$week_year) %>%
+ summarize(sessions = n()) %>%
+ group_by (HD$id, HD$name) %>%
+ summarize(avg_sessions_per_week = mean (sessions))

以下是数据集的示例:

structure(list(id = c(1010004L, 1010004L, 1010004L, 1010004L, 1010004L, 1010004L, 1010004L, 1010004L, 1010004L, 1010004L, 1010004L, 1010004L, 1010004L, 1010004L, 1010004L, 1010004L, 1010004L, 1010004L, 1010004L, 1010004L, 1010004L, 1010004L, 1010004L, 1010004L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L, 1010005L), name = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("name 1", "name 2"), class = "factor"), date = structure(c(126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L, 135L, 136L, 137L, 138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L, 147L, 148L, 149L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 91L, 92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L, 114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L, 125L), .Label = c("2003-07-31", "2003-08-01", "2003-08-02", "2003-08-04", "2003-08-06", "2003-08-08", "2003-08-11", "2003-08-13", "2003-08-15", "2003-08-18", "2003-08-20", "2003-08-22", "2003-08-25", "2003-08-27", "2003-08-28", "2003-09-01", "2003-09-03", "2003-09-05", "2003-09-06", "2003-09-08", "2003-09-10", "2003-09-11", "2003-09-12", "2003-09-13", "2003-09-15", "2003-09-16", "2003-09-17", "2003-09-19", "2003-09-20", "2003-09-22", "2003-09-23", "2003-09-24", "2003-09-25", "2003-09-26", "2003-09-27", "2003-09-29", "2003-09-30", "2003-10-01", "2003-10-02", "2003-10-03", "2003-10-04", "2003-10-06", "2003-10-08", "2003-10-10", "2003-10-11", "2003-10-13", "2003-10-15", "2003-10-16", "2003-10-17", "2003-10-18", "2003-10-20", "2003-10-22", "2003-10-24", "2003-10-27", "2003-10-28", "2003-10-29", "2003-10-30", "2003-10-31", "2003-11-01", "2003-11-03", "2003-11-04", "2003-11-06", "2003-11-08", "2003-11-10", "2003-11-11", "2003-11-12", "2003-11-13", "2003-11-15", "2003-11-17", "2003-11-19", "2003-11-21", "2003-11-22", "2003-11-24", "2003-11-26", "2003-11-28", "2003-12-01", "2003-12-03", "2003-12-05", "2003-12-08", "2003-12-10", "2003-12-12", "2003-12-15", "2003-12-17", "2003-12-19", "2003-12-22", "2003-12-24", "2003-12-27", "2003-12-29", "2003-12-31", "2004-01-03", "2004-01-05", "2004-01-07", "2004-01-09", "2004-01-12", "2004-01-14", "2004-01-16", "2004-01-19", "2004-01-21", "2004-01-23", "2004-01-26", "2004-01-28", "2004-01-30", "2004-02-02", "2004-02-04", "2004-02-06", "2004-02-09", "2004-02-11", "2004-02-13", "2004-02-16", "2004-02-18", "2004-02-20", "2004-02-23", "2004-02-25", "2004-02-27", "2004-03-01", "2004-03-03", "2004-03-05", "2004-03-08", "2004-03-10", "2004-03-12", "2004-03-15", "2004-03-17", "2004-03-19", "2004-03-22", "2004-03-24", "2007-03-22", "2007-03-24", "2007-03-26", "2007-03-27", "2007-03-30", "2007-03-31", "2007-04-02", "2007-04-04", "2007-04-06", "2007-04-07", "2007-04-09", "2007-04-11", "2007-04-13", "2007-04-15", "2007-04-16", "2007-04-18", "2007-04-20", "2007-04-23", "2007-04-25", "2007-04-27", "2007-04-28", "2007-04-30", "2007-05-02", "2007-05-04"), class = "factor"), modality = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "HD", class = "factor"), tx1 = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("2005-06-21", "2009-02-20"), class = "factor")), class = "data.frame", row.names = c(NA, -149L))

0 个答案:

没有答案