错误data.frame:选择了未定义的列,Shiny R,lapply()

时间:2018-05-08 12:03:21

标签: r shiny lapply reactive

我试图用lapply()的列平均值替换NA值。以下函数在普通R中完全正常,

 i1<- sapply(temp1, is.numeric)
    temp1[i1]<-lapply(temp[i1], function(x) replace(x,is.na(x), 
  mean(x[!is.na(x)])))

但是当我尝试相同的反应表达式时,它表示选择了未定义的列。

    num_na<-reactive({
    file1<-input$file
    temp1<-read.csv(file=file1$datapath, sep=input$sep, 
           header = input$header, stringsAsFactors = input$stringAsFactors)
  # create logical set for numeric columns
  i1<- sapply(temp1, is.numeric)
  temp1[i1]<-lapply(temp[i1], function(x) replace(x,is.na(x), 
  mean(x[!is.na(x)])))

 })

请帮我解决这个问题。它很难与反应功能一起工作。请告知此事。我正在创建另一个反应式表达式,因为我将在很多其他有光泽的actionButtons()中调用它。

0 个答案:

没有答案