0

私は R を初めて使用し、現在 RStuido を使用して手書きの数字を認識する Shiny Web アプリに取り組んでいます。

私が使用しているデータは、Kaggle コンペティションからのものです: Digit-Recogniser

数字の平均表現をレンダリングする次の関数があります

 # Produce a plot containing the average representations of digits

  output$digitAvgRep <- renderImage({

    ## For visualising traing data
    dataFrame<-as.matrix(data())

    ##Color ramp def.
    colors<-c('white','red')
    cus_col<-colorRampPalette(colors=colors)

    ## Plot the average image of each digit
    par(mfrow=c(4,3),pty='s',mar=c(1,1,1,1),xaxt='n',yaxt='n')
    all_img<-array(dim=c(10,28*28))
    for(di in 0:9)
    {
      print(di)
      all_img[di+1,]<-apply(dataFrame[dataFrame[,1]==di,-1],2,sum)
      all_img[di+1,]<-all_img[di+1,]/max(all_img[di+1,])*255

      z<-array(all_img[di+1,],dim=c(28,28))
      z<-z[,28:1] ##right side up1
      image(1:28,1:28,z,main=di,col=cus_col(256))
    }
  })

そして、次を使用して上記の変数を ui.R に渡します。

# User renderUI to dynamically create objects in the ui.R 
  output$tb <- renderUI({
    if(is.null(data()))
      h5("No data loaded.")
    else
      tabsetPanel(
        tabPanel("About file", tableOutput("filedf")),
        tabPanel("RawData", tableOutput("table")),
        tabPanel("Summary", tableOutput("sum")),
        tabPanel("Digit Distribution",plotOutput("digitDist")),
        tabPanel("Average Digit Representation", imageOutput("digitAvgRep")))
  })

アプリを実行すると、次の出力が得られます。

[1] 0
Error in all_img[di + 1, ] <- apply(dataFrame[dataFrame[, 1] == di, -1],  : 
  number of items to replace is not a multiple of replacement length

誰でもこれを解決する方法を知っていますか?

ありがとう

4

1 に答える 1