replacing NA values with mean in shiny

i want to replace NA values with mean of specific column of data set. i tried following code

ne1<-reactive({
        li3<-me2()
        
        for(i in 1:ncol(li3)){
            li3[is.na(li3[,i]), i] <- mean(li3[,i], na.rm = TRUE)
        }
        li3
    })

i got error saying argument of length 0.
why its shows length is 0?How can i solve this error

Usually argument of length 0 is caused by NULL in if statement.

For example,

X = NULL
Y = NA
Z = 1

if(is.na(X)) X = 1 
# since is.na(NULL) is logical(0), which have length 0.
# this will cause "argument of length 0" error 

if(is.na(Y)) Y = 1 
# work fine

if(is.na(Z)) Z = 1 
# work fine.

I think li3 contains NULL. I don't know what me2 function does, but you should check that first.

Regards.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.