Error : length of 'dimnames' [2] not equal to array extent

r

#1

I am currently trying to create a data frame of percentage of missing value in each variable but while creating it I am getting the error ,I want to know how to remove this error.

Percent missing value for each variable

mis_val<-sapply(startup, function(x) sum(is.na(x)))
percent_mis<-round((mis_val/nrow(startup))*100,1)

making data frame with variable and missing value percent for filtering

name<-row.names(percent_mis)
pcnt_mis_var<-cbind(name,percent_mis)
row.names(pcnt_mis_var)<-NULL
colnames(pcnt_mis_var)<-c(“variable”,“Percent.Missing”)
Error in colnames<-(*tmp*, value = c(“variable”, “Percent.Missing” :
length of ‘dimnames’ [2] not equal to array extent


#2

hi @harry,

Can you please try with the below code:

#Percent missing value for each variable:
mis_val<-sapply(churnTrain, function(x) sum(is.na(x)))
percent_mis<-data.frame(round((mis_val/nrow(churnTrain))*100,1))
percent_mis

#making data frame with variable and missing value percent for filtering:
name<-rownames(percent_mis) 
pcnt_mis_var<-cbind(name,percent_mis = percent_mis$round..mis_val.nrow.churnTrain.....100..1.)
row.names(pcnt_mis_var)<-NULL 
colnames(pcnt_mis_var)<-c("variable","Percent.Missing") 

This is basically your code only,with some changes.
Hope this helps!!