我有一个数据帧test_case.我在列(income)中缺少数据.
test_case <- data.frame(
person=c(1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3),
year=c(2010, 2011, 2012, 2010, 2011, 2012, 2010, 2011, 2013, 2014, 2014, 2014),
income=c(4, 10, 13, NA, NA, NA, 13, NA, NA, NA, NA, NA),
cutoff=c(0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0)
)
Run Code Online (Sandbox Code Playgroud)
该变量cutoff指定了我希望将收入中的值"结转"到后续行中的次数(使用包动物园中的na.locf()方法).例如,在上面的数据框中,截止值为2表示收入应该结转两次.
我已经看到关于指定如何在n为常数时使用na.locf进行n次的示例.但在我的情况下,当n正在变化时,我很难概括(R - 将前一次观察向前移动n次).
这是我的原始数据框:
person year income cutoff
1 1 2010 4 0
2 …Run Code Online (Sandbox Code Playgroud) 我刚刚使用DT. 我的问题是filter='top'实际上似乎没有执行。checkboxGroupInput从DT合并和过滤有问题吗?我希望能够添加尽可能多的过滤选项。
ui.R
library(shiny)
shinyUI(pageWithSidebar(
headerPanel('Database'),
sidebarPanel(
p('Welcome to the Database.'),
p('(1) Use the dropdown menus to select a category, type, or manufacturer.'),
p('(2) Use the checkboxes below to add or remove information from the table.'),
checkboxGroupInput('show_vars', 'Information:', names(Foods),
selected = names(Foods)),
),
mainPanel(
fluidRow(h1('A Server-side Table')),
fluidRow(
column(9, DT::dataTableOutput('x3')),
column(3, verbatimTextOutput('x4'))
)
)
)
)
server.R
library(shiny)
library(DT)
shinyServer(function(input, output, session) {
# server-side processing
output$x3 = DT::renderDataTable(Foods[, input$show_vars, drop = TRUE], server …Run Code Online (Sandbox Code Playgroud)