Error :Result must have length 12813, not 0?

落花浮王杯 提交于 2019-12-14 03:29:59

问题


I was asked to do the coding project for a job as an intern in a company but I wasnt able to complete it. However I didn't get the job I wanted to just complete the thing . The error that arrives is:

Error :Result must have length 12813, not 0

Here is my code:

library(shiny)
library(dplyr)
stock<-read.csv("thafinal2.0.csv")

ui <- fluidPage(
dateInput(inputId = 'date1',label = 'Start',value = "2017-08-20"),
dateInput(inputId = 'date2',label = 'Stop',value = "2018-08-20"),
tabPanel("stock", DT::dataTableOutput("table")))
server <- function(input, output) {
output$table<-DT::renderDataTable({
stock %>%
filter(stock$date >= "2018-01-05" & stock$date <= "2018-01-03")
stock })}

shinyApp(ui, server)

I want to select data with in a range that I want.


回答1:


Answer goes out to Dason. The problem is in code:

filter(stock$date >= "2018-01-05" & stock$date <= "2018-01-03")

You filter simultanously dates later than "2018-01-05" and earlier than "2018-01-03" this kind of operation results to empty set with length 0.

If you change to:

filter(stock$date <= "2018-01-05" & stock$date >= "2018-01-03")

It should work OK.



来源:https://stackoverflow.com/questions/53903815/error-result-must-have-length-12813-not-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!