Error: argument

Error: argument

我正在尝试创建密度直方图,但出现错误:参数 'x' 必须是数字。我尝试使用 (as.numeric(input$d)) 而不是 d 但得到了同样的错误。有谁知道如何解决这个问题?

server.R

output$hist <- renderPlot({

  input$action

  if(is.null(input$action))
    return(NULL)

  else

    isolate({

      trees3 <- FindTreesCHM(chm(), (as.numeric(input$fws)), (as.numeric(input$minht)))
      d <- density(trees3["height"])
      plot(d, xlab = "Height", ylab = "Density", main = "")
      polygon((as.numeric(input$d)), col = "darkseagreen")

    })
  })

非常感谢! :)

我认为问题出在 d <- density(trees3["height"])density 函数的第一个参数是 x 并且它应该是数字。您正在使用 [] 而不是 [[]][] return 元素列表和 [[]] return 列表中的单个元素。所以试试改变

d <- density(trees3["height"])

d <- density(trees3[["height"]]).

此外,我认为您的代码中不需要 else。但是,如果您需要使用 if...else 语句,请确保:

It is important to note that else must be in the same line as the closing braces of the if statements. http://www.programiz.com/r-programming/if-else-statement