我希望能够通过将一列除以另一列,并通过用户输入选择两个原始列来计算新的数据列。我想将此计算的数据加入到原始表(或它的副本)中。
我设法弄清楚了如何对列输入选择做出反应,并且设法进行了将一列除以另一列的计算,但是我无法制作出包含所有列的最终数据框。原始列和新计算列。
这是我使用内置的Iris数据制作的模型。它显示在第一个表中选择的列的数据,并在第二个表中显示计算(您将需要向下滚动才能看到此信息)。
如何将计算所得的数据加入原始数据源?
非常感谢
#Ui
pageWithSidebar(
headerPanel('Calculate Column'),
sidebarPanel(
#select variables from iris dataset
selectInput('xcol', 'X Variable', names(iris)),
selectInput('ycol', 'Y Variable', names(iris),
selected=names(iris)[[2]])
),
mainPanel(
#display the selected variables
tableOutput("view"),
#display the calculated variable
tableOutput("view2")
)
)
#Server
function(input, output, session) {
# Combine the selected input variables into a new data frame
selectedData <- reactive({
iris[, c(input$xcol, input$ycol),]
})
# divide one variable selection by the other
selectedData2 <- reactive({
iris$new<-iris[, c(input$xcol)]/iris[, c(input$ycol)]
})
# create data output …Run Code Online (Sandbox Code Playgroud)