我想用group_by命令创建一个闪亮的动态数据框。R闪亮的dplyr GROUP_BY命令缺失条目
所需表格的行数取决于rv $ VAR值。
由于行的数量是CL ==“1” 和CL之间不同==“2”,因为有些地区(010102,010103,160101) 没有空置的外壳,这是行不通的。
如何在表格中显示0的区域以获得每种房屋的相同行数 ?
这是我的表的一部分:
PC;COUN;DISTRICT;HOUSING;CL
01:0101; 010101; 01; 1
01:0101; 010101; 02; 1
01:0101; 010101; 03; 1
01:0101; 010101; 04; 2
01:0101; 010101; 05; 1
01:0102; 010102; 01; 1
01:0102; 010102; 02; 1
01:0102; 010102; 03; 1
01:0102; 010102; 04; 1
01:0102; 010102; 05; 1
01:0103; 010103; 01; 1
01:0103; 010103; 02; 1
01:0103; 010103; 03; 1
01:0103; 010103; 04; 1
01:0103; 010103; 05; 1
15:1501; 150101; 01; 1
15:1501; 150101; 02; 2
15:1501; 150101; 03; 1
15:1501; 150101; 04; 1
15:1501; 150101; 05; 1
16:1601; 160101; 01; 1
16:1601; 160101; 02; 1
16:1601; 160101; 03; 1
16:1601; 160101; 04; 1
21:2101; 210101; 01; 1
21:2101; 210101; 02; 1
21:2101; 210101; 03; 2
21:2101; 210101; 04; 1
21:2101; 210101; 05; 2
25:2501; 250101; 01; 1
25:2501; 250101; 02; 1
25:2501; 250101; 03; 1
这是我写的代码的一部分:
selectionAcc_View <- reactive({
if (rv$CHAMP == "DISTRICT") {
selectionAccomodations <- reactive({
return(filter(myTable, DISTRICT %in% rv$VAR))})
tmp <- selectionAccomodations()
dfACC <- tmp %>%
group_by(DISTRICT) %>%
summarize(Accomodations=n())
dfMA <- filter(tmp, CL == "1" %>%
group_by(DISTRICT) %>%
summarize(MA=n())
dfVH <- filter(tmp, CL == "2" %>%
group_by(DISTRICT) %>%
summarize(VH=n())
# Create table
df <- data.frame(
Total_Accomodations = c(dfACC$Accomodations), # Number of Accomodations
Main_Accomodations = c(dfMA$MA), # Number of Main Accomodations
Vacant_Housings = c(dfVH$VH) # Number of Vacant Housings
) # end of data.frame
} # end of if
df
}) # End of selectionAcc_View <- reactive({
# Output the table
output$df <- renderDataTable(selectionAcc_View(),options = list(paging =
FALSE, ordering = FALSE,searching = FALSE,info = FALSE))
}) # End of shinyServer(function(input, output, session) {
请,你有一个想法?
非常感谢。
太伟大了!我印象深刻,这正是我想要做的。我将调整你的代码到我的程序中。非常感谢Mike。 –
好的。也会赞赏upvote。 –
对不起,您是否问我点击分辨率标记上方的向上箭头?如果是的话,那就完成了,非常感谢你。 –