小编Jst*_*d3r的帖子

使用R Shiny中的动态输入构建线性回归

我正在尝试使用线性回归构建一个简单的闪亮应用程序,允许用户选择lm()函数中使用的独立变量和因变量,并最终绘制出几个图表.我目前坚持将输入传递给服务器端的lm()函数,并且能够打印出回归的摘要.任何人都可以帮助我解决我的逻辑/代码出错的问题.下面是代码

library(shiny)
library(data.table)

RegData <- as.data.table(read.table("/home/r2uphp/ShinyApps/IRViews/RegData.tsv", header = TRUE, stringsAsFactors = FALSE))

ui <- fluidPage(
  headerPanel("Regression and Time Series Analysis"), 
  sidebarPanel(
    p("Select the inputs for the Dependent Variable"),
    selectInput(inputId = "DepVar", label = "Dependent Variables", multiple = FALSE, choices = list("AvgIR", "YYYYMM", "SumCount", "AvgLTV", "AvgGFEE", "AvgRTC", "Date")),
    p("Select the inputs for the Independent Variable"),
    selectInput(inputId = "IndVar", label = "Independent Variables", multiple = FALSE, choices = list( "SumCount", "AvgIR", "YYYYMM", "AvgLTV", "AvgGFEE", "AvgRTC", "Date"))
  ),
  mainPanel(
    verbatimTextOutput(outputId = "RegSum"),
    verbatimTextOutput(outputId …
Run Code Online (Sandbox Code Playgroud)

r shiny

8
推荐指数
1
解决办法
4317
查看次数

tidyverse 方法使用用户提供的参数(如果不是 NULL 或默认值)

我的目标是使用 tidyverse 有条件地改变数据类型。这是一个可重现的示例。例如,我想将列更改cyl为因子。然而,因子\xe2\x80\x99slevelslabels参数将取决于用户是否提供了对象bin.order或留下了它NULL。我知道如何在 tidyverse 之外执行此操作,但通过 tidyverse 函数寻找更简洁的方法。

\n
mtcars %>% \n  mutate(cyl = ifelse(is.null(bin.order), \n                      factor(x = cyl, levels = sort(unique(cyl)), labels = sort(unique(cyl))), \n                      factor(x = cyl, levels = bin.order, labels = bin.order)))\n
Run Code Online (Sandbox Code Playgroud)\n

期望的结果将是这样的:

\n
# if bin.order is null\nmtcars %>% \n  mutate(cyl = factor(x = cyl, levels = sort(unique(cyl)), labels = sort(unique(cyl))))\n\n# if bin.order is not null\nbin.order = c(4, 6, 8)\nmtcars %>% \n  mutate(cyl = factor(x = …
Run Code Online (Sandbox Code Playgroud)

r dplyr

1
推荐指数
1
解决办法
75
查看次数

标签 统计

r ×2

dplyr ×1

shiny ×1