在 Fantasy Football 阵容优化器中添加 Flex 位置

2024-04-19

我编写了一些 R 代码来生成最佳的幻想足球阵容(最大化预计得分),该阵容受到用户输入的名单大小和选秀预算的约束,该数据框基于称为“球员”的数据框,该数据框由球员、位置、幻想点和选秀组成价值。

我们的想法是在选秀之前使用这个工具(记住理想的阵容),然后在选秀时实时更新它,因为最佳阵容很可能是一个流动的事情。

我对如何包含“弹性”位置感到困惑,该位置是一个可以是 RB、WR 或 TE 的名单位置。我目前隐式地将其包含在 num_players 约束中 - 如果您的联赛需要 1 个 qb、2 个 rb、2 个 wr、1 个 te 和 1 个弹性位置,则您的 num_players 输入应该为 7。目前,此代码仅在 num_players = qb 时才有效+rb+wr+te 无弯曲(本例中为 6)。当我将 num_players 约束设置为比该总数多 1 并尝试包含一个弹性位置时,它会中断。

如何更新此代码以删除隐式 num_players 约束并包含 Flexes 约束?

数据框是:

players <- structure(list(Player = c("Josh Allen", "Patrick Mahomes", "Justin Herbert", 
"Lamar Jackson", "Kyler Murray", "Jalen Hurts", "Tom Brady", 
"Dak Prescott", "Joe Burrow", "Russell Wilson", "Aaron Rodgers", 
"Trey Lance", "Matthew Stafford", "Kirk Cousins", "Derek Carr", 
"Tua Tagovailoa", "Justin Fields", "Trevor Lawrence", "Ryan Tannehill", 
"Daniel Jones", "Matt Ryan", "Jameis Winston", "Carson Wentz", 
"Mac Jones", "Jared Goff", "Zach Wilson", "Davis Mills", "Baker Mayfield", 
"Marcus Mariota", "Deshaun Watson", "Mitchell Trubisky", "Geno Smith", 
"Drew Lock", "Kenny Pickett", "Jacoby Brissett", "Desmond Ridder", 
"Travis Kelce", "Mark Andrews", "Kyle Pitts", "Darren Waller", 
"George Kittle", "Dalton Schultz", "T.J. Hockenson", "Dallas Goedert", 
"Zach Ertz", "Dawson Knox", "Hunter Henry", "Mike Gesicki", "Pat Freiermuth", 
"Cole Kmet", "Irv Smith Jr.", "Noah Fant", "Tyler Higbee", "David Njoku", 
"Albert Okwuegbunam", "Gerald Everett", "Robert Tonyan", "Jonathan Taylor", 
"Christian McCaffrey", "Derrick Henry", "Austin Ekeler", "Dalvin Cook", 
"Joe Mixon", "Najee Harris", "Alvin Kamara", "D'Andre Swift", 
"Leonard Fournette", "Saquon Barkley", "Aaron Jones", "Nick Chubb", 
"James Conner", "Javonte Williams", "Ezekiel Elliott", "David Montgomery", 
"Cam Akers", "Travis Etienne Jr.", "Breece Hall", "J.K. Dobbins", 
"Josh Jacobs", "Antonio Gibson", "Elijah Mitchell", "AJ Dillon", 
"Cordarrelle Patterson", "Damien Harris", "Miles Sanders", "Clyde Edwards-Helaire", 
"Tony Pollard", "Devin Singletary", "Kareem Hunt", "Chase Edmonds", 
"Rashaad Penny", "Rhamondre Stevenson", "Kenneth Walker III", 
"Melvin Gordon III", "Darrell Henderson Jr.", "James Robinson", 
"James Cook", "Dameon Pierce", "Michael Carter", "Jamaal Williams", 
"Nyheim Hines", "J.D. McKissic", "Kenneth Gainwell", "Alexander Mattison", 
"Isaiah Spiller", "Raheem Mostert", "Mark Ingram II", "Marlon Mack", 
"Brian Robinson", "Gus Edwards", "Rex Burkhead", "Rachaad White", 
"Khalil Herbert", "Damien Williams", "Tyler Allgeier", "D'Onta Foreman", 
"Jerick McKinnon", "Cooper Kupp", "Justin Jefferson", "Ja'Marr Chase", 
"Davante Adams", "Stefon Diggs", "Deebo Samuel", "CeeDee Lamb", 
"Mike Evans", "Tyreek Hill", "Tee Higgins", "Keenan Allen", "DJ Moore", 
"A.J. Brown", "Michael Pittman Jr.", "Mike Williams", "Brandin Cooks", 
"Jaylen Waddle", "Diontae Johnson", "Terry McLaurin", "DK Metcalf", 
"Courtland Sutton", "Amon-Ra St. Brown", "Darnell Mooney", "Allen Robinson II", 
"Marquise Brown", "Amari Cooper", "Gabriel Davis", "Chris Godwin", 
"Michael Thomas", "Jerry Jeudy", "Adam Thielen", "JuJu Smith-Schuster", 
"Hunter Renfrow", "Rashod Bateman", "Elijah Moore", "Tyler Lockett", 
"Christian Kirk", "Robert Woods", "DeVonta Smith", "Drake London", 
"Allen Lazard", "Brandon Aiyuk", "Chase Claypool", "Kadarius Toney", 
"Tyler Boyd", "Garrett Wilson", "DeVante Parker", "Chris Olave", 
"Kenny Golladay", "Jakobi Meyers", "Russell Gage", "Marquez Valdes-Scantling", 
"DeAndre Hopkins", "Marvin Jones Jr.", "Treylon Burks", "Michael Gallup", 
"Robbie Anderson", "DJ Chark", "Jahan Dotson", "Mecole Hardman"
), Position = c("QB", "QB", "QB", "QB", "QB", "QB", "QB", "QB", 
"QB", "QB", "QB", "QB", "QB", "QB", "QB", "QB", "QB", "QB", "QB", 
"QB", "QB", "QB", "QB", "QB", "QB", "QB", "QB", "QB", "QB", "QB", 
"QB", "QB", "QB", "QB", "QB", "QB", "TE", "TE", "TE", "TE", "TE", 
"TE", "TE", "TE", "TE", "TE", "TE", "TE", "TE", "TE", "TE", "TE", 
"TE", "TE", "TE", "TE", "TE", "RB", "RB", "RB", "RB", "RB", "RB", 
"RB", "RB", "RB", "RB", "RB", "RB", "RB", "RB", "RB", "RB", "RB", 
"RB", "RB", "RB", "RB", "RB", "RB", "RB", "RB", "RB", "RB", "RB", 
"RB", "RB", "RB", "RB", "RB", "RB", "RB", "RB", "RB", "RB", "RB", 
"RB", "RB", "RB", "RB", "RB", "RB", "RB", "RB", "RB", "RB", "RB", 
"RB", "RB", "RB", "RB", "RB", "RB", "RB", "RB", "RB", "RB", "WR", 
"WR", "WR", "WR", "WR", "WR", "WR", "WR", "WR", "WR", "WR", "WR", 
"WR", "WR", "WR", "WR", "WR", "WR", "WR", "WR", "WR", "WR", "WR", 
"WR", "WR", "WR", "WR", "WR", "WR", "WR", "WR", "WR", "WR", "WR", 
"WR", "WR", "WR", "WR", "WR", "WR", "WR", "WR", "WR", "WR", "WR", 
"WR", "WR", "WR", "WR", "WR", "WR", "WR", "WR", "WR", "WR", "WR", 
"WR", "WR", "WR", "WR"), FantasyPoints = c(445, 410, 407, 348, 
351, 359, 354, 364, 402, 368, 353, 347, 349, 335, 366, 325, 297, 
313, 273, 283, 302, 284, 275, 296, 291, 0, 247, 286, 276, 0, 
0, 0, 0, 269, 0, 0, 252, 231, 206, 171, 185, 177, 174, 169, 169, 
171, 139, 131, 170, 170, 162, 129, 162, 119, 130, 126, 130, 340, 
285, 260, 278, 277, 271, 277, 247, 271, 225, 247, 249, 230, 196, 
268, 205, 199, 213, 231, 220, 177, 176, 159, 178, 185, 155, 181, 
157, 190, 177, 164, 156, 166, 169, 179, 158, 129, 147, 99, 158, 
176, 150, 100, 157, 128, 156, 124, 98, 95, 75, 90, 136, 80, 82, 
143, 128, 0, 147, 97, 63, 326, 337, 308, 299, 269, 267, 271, 
242, 243, 241, 239, 243, 242, 244, 209, 220, 233, 239, 221, 198, 
221, 209, 220, 209, 218, 178, 224, 183, 186, 203, 188, 164, 207, 
211, 202, 173, 188, 163, 199, 171, 181, 182, 140, 170, 175, 144, 
142, 164, 147, 131, 170, 160, 182, 136, 153, 157, 152, 148, 175, 
144), DraftValue = c(31, 23, 20, 15, 16, 14, 16, 11, 12, 10, 
10, 3, 7, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 37, 34, 22, 20, 17, 16, 12, 11, 9, 6, 4, 4, 
5, 5, 2, 2, 2, 1, 1, 1, 1, 56, 55, 44, 48, 38, 38, 40, 38, 36, 
34, 34, 33, 27, 30, 28, 27, 23, 21, 23, 21, 19, 18, 10, 15, 16, 
16, 12, 12, 14, 13, 10, 11, 12, 8, 9, 1, 6, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 56, 48, 41, 
40, 37, 31, 34, 29, 30, 28, 28, 26, 24, 26, 23, 23, 22, 21, 20, 
18, 19, 20, 17, 18, 17, 15, 15, 17, 17, 16, 16, 15, 15, 13, 12, 
12, 12, 11, 9, 9, 9, 7, 5, 6, 4, 2, 2, 2, 1, 3, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, 
-177L))

应用程序代码是:

library(shiny)
library(lpSolve)
library(purrr)
library(rsconnect)


# Define the UI for the app
ui <- fluidPage(
  titlePanel("Fantasy Football Lineup Optimizer"),

  sidebarLayout(
    sidebarPanel(
      numericInput("num_qb", "Enter the number of QBs:", 1, min = 1, max = 5),
      numericInput("num_rb", "Enter the number of RBs:", 3, min = 1, max = 5),
      numericInput("num_wr", "Enter the number of WRs:", 3, min = 1, max = 5),
      numericInput("num_te", "Enter the number of TEs:", 2, min = 1, max = 5),
      numericInput("num_value", "Enter your draft budget:", 200),
      numericInput("num_players", "Adding in your flex spots, enter the total number of starters:", 9, min = 1, max = 15),
      selectInput("remove", "Remove a player:", choices = c("",as.character(players$Player)), multiple = FALSE),
      selectInput("draft_player", "Draft Player", choices = c("",as.character(players$Player)), multiple = FALSE),
      actionButton("update", "Update Lineup")
    ),
    mainPanel(
      tableOutput("team")
    )
  )
)

# Define the server logic
server <- function(input, output, session) {
  players <- players

  # New col to indicate if a player has been drafted
  players$Drafted = "No"

  # Create a new column indicating the player's position
  players$QB <- ifelse(players$Position == "QB", 1, 0)
  players$RB <- ifelse(players$Position == "RB", 1, 0)
  players$WR <- ifelse(players$Position == "WR", 1, 0)
  players$TE <- ifelse(players$Position == "TE", 1, 0)
  players$Total <- 1
  rv <- reactiveValues(players=players)

  # Set up reactive table for lineup output
  updateLineup = reactiveVal(NULL)

  # Define the objective function (maximize fantasy points)
  obj <- players$FantasyPoints

  # Define the constraints (position limits and draft value limit)
  con <- reactive({
    matrix(c(
        # QB constraint
        rv$players$QB,
        # RB constraint
        rv$players$RB,
        # WR constraint
        rv$players$WR,
        # TE constraint
        rv$players$TE,
        # Draft value constraint
        rv$players$DraftValue,
        #Total players constraint
        rv$players$Total
    ), ncol = nrow(rv$players), byrow = TRUE)
  })

  # Define the variables for the lp
  dir <- c("<=", rep(">=",3),"<=","<=")

  # Define initial 'const.rhs'
  init_rhs <- reactive({
    list(
      QB = input$num_qb,
      RB = input$num_rb,
      WR = input$num_wr,
      TE = input$num_te,
      n_val = input$num_value,
      n_players = input$num_players
    )
  })

  # Define reactive 'const.rhs'
  rhs = reactiveValues(const = list())

  # Run once to get the initial values and set them to reactiveValues
  # so they can be changed later
  observeEvent(init_rhs(),{
    rhs$const = init_rhs()
  }, once = TRUE)

  # Define the initial optimal lineup
  initialLineup <- reactive({
    result <- lp("max", obj, con(), dir, init_rhs(), all.bin = TRUE)
    rv$players[result$solution == 1,]
  })

  # Define the function to run when the "update" button is pressed
  observeEvent(input$update, {
    # Remove player here
    if(input$remove != "") {
      removedPlayer <- input$remove
      rv$players <- rv$players[rv$players$Player != removedPlayer,]
      obj <- rv$players$FantasyPoints
    }

    # Draft player
    if(input$draft_player != "") {
      draftedPlayer <- input$draft_player
      draftedPlayer_details <- rv$players[rv$players$Player == draftedPlayer,]
      draftedPlayer_details$Drafted = "Yes"
      rv$players <- rv$players[rv$players$Player != draftedPlayer,]
      rv$draftedPlayers <- rbind(rv$draftedPlayers, draftedPlayer_details)
      obj <- rv$players$FantasyPoints # missing object

      # Subtract constraints: position and n_players by 1 and draft budget by the players 'DraftValue'
      # Necessary so "result" outputs a table with the remaining positions left
      # otherwise it will return an entirely new lineup
      rhs$const = purrr::imap(rhs$const, function(cs, nm) {
        if(nm == draftedPlayer_details$Position) {cs = cs - 1}
        if(nm == "n_players") {cs = cs - 1}
        if(nm == "n_val") {cs = cs - draftedPlayer_details$DraftValue}
        return(cs)
      })
    }

    # Update select inputs to remove players after "Update Lineup" is clicked
    if(input$remove != "" || input$draft_player != "") {
      updateSelectInput(session, inputId = "remove", choices = c("",rv$players), selected = "")
      updateSelectInput(session, inputId = "draft_player", choices = c("",rv$players), selected = "")
    }

    # Define result with updated arguments
    result <- lp("max", obj, con(), dir, rhs$const, all.bin = TRUE)
    # Assign new table to the reactiveVal 'updateLineup'
    updateLineup(rbind(rv$draftedPlayers, rv$players[result$solution == 1,]))
  })

  output$team <- renderTable({
    if (input$update == 0) {
      initialLineup()[, c("Player", "Position", "FantasyPoints", "DraftValue", "Drafted")]
    } else {
      updateLineup()[, c("Player", "Position", "FantasyPoints", "DraftValue", "Drafted")]
    }
  })
}

# Run the app
shinyApp(ui, server)

这是包含弹性位置的选项。我依靠 det 的响应来更新应用程序上下文中的约束。

正如 det 提到的,您需要使用 Flex 特定位置更新约束矩阵。在本例中是 RB、WR 和 TE。然后定义新约束的方向。这里的关键是对你的弯曲使用“

然后,您可以设置约束的 rhs 值。您需要添加与flex相关的组件。我通过从首发总数中减去位置输入的总和来定义弹性点的数量。

最后,为了使其按预期工作,我添加了一个新按钮“设置草稿约束”。单击后,这将永久设置草稿的约束。如果您需要进行更改,则需要重新加载应用程序。在开始草稿过程之前必须先单击它。

App code

library(shiny)
library(lpSolve)
library(purrr)
library(shinyjs)

# Define the UI for the app
ui <- fluidPage(
  useShinyjs(),
  titlePanel("Fantasy Football Lineup Optimizer"),

  sidebarLayout(
    sidebarPanel(
      numericInput("num_qb", "Enter the number of QBs:", 1, min = 1, max = 5),
      numericInput("num_rb", "Enter the number of RBs:", 2, min = 1, max = 5),
      numericInput("num_wr", "Enter the number of WRs:", 2, min = 1, max = 5),
      numericInput("num_te", "Enter the number of TEs:", 1, min = 1, max = 5),
      numericInput("num_value", "Enter your draft budget:", 200),
      numericInput("num_players", "Adding in your flex spots, enter the total number of starters:", 9, min = 1, max = 15),
      actionButton("set_const", "Set Draft Constraints"),
      selectInput("remove", "Remove a player:", choices = c("",as.character(players$Player)), multiple = FALSE),
      selectInput("draft_player", "Draft Player", choices = c("",as.character(players$Player)), multiple = FALSE),
      actionButton("update", "Update Lineup")
    ),
    mainPanel(
      tableOutput("team")
    )
  )
)

# Define the server logic
server <- function(input, output, session) {
  players <- players

  # New col to indicate if a player has been drafted
  players$Drafted = "No"

  # Create a new column indicating the player's position
  players$QB <- ifelse(players$Position == "QB", 1, 0)
  players$RB <- ifelse(players$Position == "RB", 1, 0)
  players$WR <- ifelse(players$Position == "WR", 1, 0)
  players$TE <- ifelse(players$Position == "TE", 1, 0)
  players$Total <- 1
  rv <- reactiveValues(players=players)

  # Set up reactive table for lineup output
  updateLineup = reactiveVal(NULL)

  # Define the objective function (maximize fantasy points)
  obj <- players$FantasyPoints

  # Define the constraints (position limits and draft value limit)
  con <- reactive({
    matrix(c(
        # Position constraint
        rv$players$QB,
        rv$players$RB,
        rv$players$WR,
        rv$players$TE,
        # Flex constraints
        rv$players$RB,
        rv$players$WR,
        rv$players$TE,
        #Total players constraint
        rv$players$Total,
        # Draft value constraint
        rv$players$DraftValue
    ), ncol = nrow(rv$players), byrow = TRUE)
  })

  # Define the variables for the lp
  dir <- c("<=",rep(">=",3),rep("<=",3),"==","<=")

  # Define num of flex spots
  flex_spots = reactive(input$num_players - sum(input$num_qb,input$num_rb,input$num_wr,input$num_te))

  # Define initial 'const.rhs'
  init_rhs <- reactive({
    list(
      QB = input$num_qb,
      RB = input$num_rb,
      WR = input$num_wr,
      TE = input$num_te,
      RB_flex = input$num_rb + flex_spots(),
      WR_flex = input$num_wr + flex_spots(),
      TE_flex = input$num_te + flex_spots(),
      n_players = input$num_players,
      n_val = input$num_value
    )
  })

  # Define reactive 'const.rhs'
  rhs = reactiveValues(const = list())

  # Define the initial optimal lineup
  initialLineup <- reactive({
    result <- lp("max", obj, con(), dir, init_rhs(), all.bin = TRUE)
    rv$players[result$solution == 1,]
  })
  
  # Set constraints and disable draft inputs
  observeEvent(input$set_const, {
    disable(selector = "input[type = 'number']")
    disable(id = "set_const")
    rhs$const = init_rhs()
  })

  # Define the function to run when the "update" button is pressed
  observeEvent(input$update, {
    if(input$set_const == 0) { stop("Please set draft constraints first") }
    
    # Remove player here
    if(input$remove != "") {
      removedPlayer <- input$remove
      rv$players <- rv$players[rv$players$Player != removedPlayer,]
      obj <- rv$players$FantasyPoints
    }

    # Draft player
    if(input$draft_player != "") {
      draftedPlayer <- input$draft_player
      draftedPlayer_details <- rv$players[rv$players$Player == draftedPlayer,]
      draftedPlayer_details$Drafted = "Yes"
      rv$players <- rv$players[rv$players$Player != draftedPlayer,]
      rv$draftedPlayers <- rbind(rv$draftedPlayers, draftedPlayer_details)
      obj <- rv$players$FantasyPoints # missing object

      # Subtract constraints: position and n_players by 1 and draft budget by the players 'DraftValue'
      # Necessary so "result" outputs a table with the remaining positions left
      # otherwise it will return an entirely new lineup
      rhs$const = purrr::imap(rhs$const, function(cs, nm) {
        if(nm == draftedPlayer_details$Position) {cs = cs - 1}
        if(nm == "n_players") {cs = cs - 1}
        if(nm == "n_val") {cs = cs - draftedPlayer_details$DraftValue}
        return(cs)
      })
    }

    # Update select inputs to remove players after "Update Lineup" is clicked
    if(input$remove != "" || input$draft_player != "") {
      updateSelectInput(session, inputId = "remove", choices = c("",rv$players), selected = "")
      updateSelectInput(session, inputId = "draft_player", choices = c("",rv$players), selected = "")
    }

    # Define result with updated arguments
    result <- lp("max", obj, con(), dir, rhs$const, all.bin = TRUE)
    # Assign new table to the reactiveVal 'updateLineup'
    updateLineup(rbind(rv$draftedPlayers, rv$players[result$solution == 1,]))
  })

  output$team <- renderTable({
    if (input$update == 0) {
      initialLineup()[, c("Player", "Position", "FantasyPoints", "DraftValue", "Drafted")]
    } else {
      updateLineup()[, c("Player", "Position", "FantasyPoints", "DraftValue", "Drafted")]
    }
  })
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Fantasy Football 阵容优化器中添加 Flex 位置 的相关文章

  • R 中的 as.numeric 有什么问题? [复制]

    这个问题在这里已经有答案了 gt X864291X8X74 1 8 0000000000 9 0000000000 10 0000000000 6 0000000000 8 0000000000 10 Levels 0 0000000000
  • 根据不平凡的标准有效合并两个数据帧

    正在接听这个问题 https stackoverflow com questions 18821862 data selection error 18823432 18823432昨晚 我花了一个小时试图找到一个没有增长的解决方案data
  • 在单个显示器中绘制多个 jpeg 图像

    我需要在单个组合显示器 或画布 中绘制和显示多个 jpeg 图像 例如 假设我有图像 a b c d jpg 每个图像的大小不同 我想将它们绘制在 2x2 网格的一页上 能够为每个子图设置标题也很好 我一直在彻底寻找解决方案 但不知道如何去
  • 删除 R 中具有重复属性的行

    我有一个大数据框 其中包含以下列 ID time OS IP 该数据帧的每一行对应一个条目 在该数据框中对于某些IDs存在多个条目 行 我想删除这些多行 显然 同一 ID 的其他属性会有所不同 或者换句话说 我只想要每个 ID 一个条目 行
  • std::类似向量的类经过优化以容纳少量项目[重复]

    这个问题在这里已经有答案了 在程序的一个时间关键部分中 有一个类成员如下所示 std vector m vLinks 在分析过程中 我注意到该向量大约 99 98 的执行仅包含 0 或 1 个项目 然而 在极少数情况下 它可能会容纳更多 根
  • read.table 和 read.delim 函数之间的区别

    两者有什么区别read table and read delim R语言中的函数 当您不确定函数的作用时 除了阅读帮助页面之外 您还可以检查函数的实际代码 例如 输入read delim显示该函数包含以下代码 gt read delim f
  • R-在多个图的外缘绘制居中图例

    我想在具有多个绘图的设备中的绘图区域之外绘制居中图例 SO 中提出了许多关于更改 R 图中图例位置的问题 略有不同 例如 1 R 组合图的通用标题和图例 https stackoverflow com questions 8736966 r
  • 优化 R 中的嵌套 for 循环

    我尝试加速下面的代码 但没有成功 我读到Rfast https cran r project org web packages Rfast Rfast pdf包 但我也未能实现该包 有没有办法优化R中的以下代码 RI lt function
  • 在 Shiny 应用程序中过滤数据时,长度为 1 的字符向量除了第一个元素之外的所有元素都将被忽略错误

    我有以下闪亮的应用程序 library shiny library rhandsontable library shinydashboard library ggplot2 library dplyr setwd C Users Marc
  • R lubridate:当地语言的工作日

    如何获取本地语言的工作日和月份 My code library lubridate data lt c 10 02 2015 11 03 2015 data lubri lt dmy data wday data lubri label T
  • 无法在 Document-Term-Matrix 中看到 `RTextTools::toLower()` 文本的结果

    我尝试创建一个矩阵 为此我想降低文本 为此 我使用此 R 指令 matrix create matrix tweets 1 toLower TRUE language english removeStopwords FALSE remove
  • 将 read.csv 与符号链接文件一起使用

    我正在尝试做什么 我的源文件非常大 我想避免将其复制到其他文件夹中 我决定创建一个指向大文件的符号链接并想使用read csv读取文件 文件夹结构 项目1 数据 源文件 csv 项目2 数据 别名到源文件 csv 什么地方出了错 读取源文件
  • 在 R 中将时间间隔数据扩展为天数

    假设我有如下所示的数据 interval id indiv id role start date end date 1 1 A 2006 05 01 2006 06 16 2 1 B 2006 06 16 2006 10 16 3 1 A
  • 如何将 R 数据框中的多个字符列合并为单个列

    我正在处理人口普查数据 需要将四个字符列合并为一列 Example LOGRECNO STATE COUNTY TRACT BLOCK 60 01 001 021100 1053 61 01 001 021100 1054 62 01 00
  • 从向量中删除元素在 R 中出现的时间量

    我想从一个向量中删除元素在另一个向量中出现的时间 就像我要减去它们一样 鉴于我想要删除的元素向量中的每个元素也存在于我想要从中删除的主向量中 a lt c A B B C C C b lt c A B C C a a in b return
  • 在 Shiny 中叠加两个 ggplot

    我有一个非常大的数据集 我正在使用 ggplot 在 Shiny 上绘制它 我有一个与 x 轴上的值相关联的滑块 我想用它对选定的数据子集重新着色 并让其余数据保持原样 最简单的选择是重新创建整个绘图 但由于它是一个大型数据集 因此这是一个
  • 使用 readHTMLTable 从 https 网页读取表格

    我安装了 R 3 3 1 并使用 RStudio 0 99 903 我正在尝试从以下 URL 将表格读入 R https www fantasypros com nfl rankings consensus cheatsheets php
  • R:如何找到向量的模式[重复]

    这个问题在这里已经有答案了 下面是我的data frame我想知道每个内存类别 1 到 8 的模式是什么 gt dput d structure list MEMORY1 c 5 5 7 1 5 6 4 5 4 5 5 4 1 5 5 2
  • matplotlib 中的 R 风格数据轴缓冲区

    R 绘图自动设置 x 和 y 限制 以在数据和轴之间留出一些空间 我想知道 matplotlib 是否有办法自动执行相同的操作 如果没有 是否有一个好的公式或 经验法则 来说明 R 如何设置其轴限制 在 matplotlib 中 您可以通过
  • ggplot 图例标签内的希腊字母、符号和换行符

    我在尝试着 有换行符 自动或强制 对齐文本 左对齐或左右对齐 有希腊字母和百分号 在 gglot 图例标签内 我尝试了几种方法 但我似乎无法将我读到的所有技巧结合起来 我可以通过插入来换行 n进入标签 但这似乎不适用于希腊字母 不适用于图例

随机推荐

  • Laravel - 如何获取特定用户的委托角色

    我正在用 Laravel 做一个小工作并使用齐扎科信托公司 以管理员身份登录时我想查看全部Roles特定用户的 我搜索了一段时间但没有找到任何线索 我怎样才能使用Entrust或者我应该使用 SQL 查询吗 在您的 User 类中添加 pu
  • Windows 服务器上的 PTP 同步(与 Linux 相比) - 可以保证什么精度

    我想知道大家是否知道准确度如何PTP http en wikipedia org wiki Precision Time Protocol在 Windows Server 2008 上可以保证同步 我知道这个线程 Windows 中进程的最
  • 访问 Google Chrome 的缓存

    是否可以从扩展程序中访问 Google Chrome 的缓存 我想编写一个扩展 当无法访问在线页面时 例如互联网连接问题 加载页面的缓存版本 Updated 我知道我可以编写一个可通过扩展访问的 NPAPI 插件来完成此任务 但我不想编写一
  • Firestore 客户和发票,修订后的要求

    这个问题是此处发布的问题的后续问题 Firestore 客户和发票 如何建模 https stackoverflow com questions 50867267 firestore clients and invoices how to
  • C++ 错误:没有调用“print_size”的匹配函数

    我有这个代码 include
  • 为什么函数 printk() 不使用逗号来分隔参数?

    一个例子printk call printk KERN INFO Log message n 也许这个问题更多地是关于C的 因为我之前从未见过C中的函数可以不用逗号分隔参数 这是如何运作的 编译器如何处理这些信息 由于日志级别是一个整数 而
  • 在没有正确原型的情况下调用 printf 是否会引发未定义的行为?

    这个看起来无辜的程序是否会调用未定义的行为 int main void printf d n 1 return 0 是的 调用printf 没有适当的原型 来自标准头
  • python:单行笛卡尔积for循环

    你知道你能做到吗 gt gt gt x y for x in xrange 2 for y in xrange 5 0 0 0 1 0 2 0 3 0 4 1 0 1 1 1 2 1 3 1 4 很整洁 是否有 for 循环版本或者只能对列
  • Flash AS3 - 将多个对象拖放到一个目标?

    标题或多或少是不言自明的 我一直在学习许多不同的教程 而且说实话 我对 AS3 不太擅长 上图显示了我的目标 无论如何 我在我看到的大多数在线教程中注意到 拖放教程要么基于一个对象到一个目标 要么基于多个对象到多个目标 所以我想知道是否有人
  • 如何让php函数每5秒循环一次

    我正在尝试创建一个每秒更新一次的 php 函数 使用 php 本身 没有其他语言 只是纯 PHP 代码 function exp do something 我希望它每秒返回一个值 就像每秒更新一样 对于应用程序服务器 不是 Web 服务器
  • 让 WordPress 使用页面而不是类别

    我做了大量的研究并发现了一些像这样的解决方案 https wordpress stackexchange com questions 106042 force wordpress to show pages instead of categ
  • VS 2008 Addon 暂时禁用/删除所有 catch 块

    是否有任何插件可以暂时禁用所有 catch 块 我正在维护一个应用程序 我需要找出它到底在哪里抛出异常 有人已经完成了错误处理 所有层都完成了 这使我的工作变得艰难 我不知道如何禁用 catch 块 但您想要实现的目标可以通过异常对话框中的
  • 如何设置微调器下拉列表的最大长度?

    我有一个微调器 当前打开时会遮挡微调器下方的一些文本 我需要通过 java 代码或 XML 来限制微调器的最大下拉长度 这样它就不会模糊此文本 The current design is the left example while the
  • 获取错误消息

    我们使用以下代码在验证文档时添加新的错误消息 function addFacesMessage message component try if typeof component string component getComponent
  • Firebase Push() 与 Angularfire $save()

    angularfire save 与 firebase push 相比如何 我知道 Push 在存储数据时会生成一个唯一的密钥 但我无法使用 AngularFire 重新创建该行为 有没有办法或者我应该使用 push 如果是这样 在什么情况
  • 消除在 Swift 中连续绘制 UIBezierPath 期间的滞后延迟

    下面的代码通过覆盖触摸来绘制线条 但是在连续不间断绘制的一段时间内开始出现滞后 手指在屏幕上移动的时间越长 这种滞后就会累积并变得更严重 结果是实际设备上的 CPU 几乎达到极限 CPU 98 并且绘图持续时间越长 生成的图像看起来就越不稳
  • 获取 Disqus html 代码以显示在源代码中以实现 SEO 目的

    最近开始在网站上使用 Disqus 想知道是否有任何方法可以让实际的 html 代码显示在源页面中 我注意到这个网站正在这样做 http adamkaras com blog 2009 06 24 disqus custom css sty
  • 鼠标悬停 div 时弹出消息

    尝试让一个简单的弹出窗口出现mouseover a div我按照答案使用 onmouseover 的描述框 https stackoverflow com questions 3559467 description box on mouse
  • 如何从 java.util.Map 转换为 Scala Map

    Java API 返回一个java util Map
  • 在 Fantasy Football 阵容优化器中添加 Flex 位置

    我编写了一些 R 代码来生成最佳的幻想足球阵容 最大化预计得分 该阵容受到用户输入的名单大小和选秀预算的约束 该数据框基于称为 球员 的数据框 该数据框由球员 位置 幻想点和选秀组成价值 我们的想法是在选秀之前使用这个工具 记住理想的阵容