R studio error : Error in x[[jj]][iseq] <- vjj : replacement has length zero

r

#1

Hi guys,
I got asked to try to put missing values, but I don’t really understand it.
when I run this code:

c.ID <- c( NutSur2014[is.na(NutSur2014$Birthweight), "ID"],
           NutSur2014[which(NutSur2014$Birthweight%in%c(777, 7777, 888, 8888)),  "ID"])
c.Ward <- unique(NutSur2014[which(NutSur2014$ID%in%c.ID& NutSur2014$Ward != "2707"), "Ward"])

for (c in c.Ward)
{
  repvalue <- as.numeric(names(which.max(table(NutSur2014[which((!NutSur2014$ID%in%c.ID) & NutSur2014$Ward == c),
                                                          "Birthweight"])))) 
  NutSur2014[which(NutSur2014$ID%in%c.ID & NutSur2014$Ward == c), "Birthweight"] <- repvalue 
}

I get an error namely:

Error in x[[jj]][iseq] <- vjj : replacement has length zero

What does “Error in x[[jj]][iseq] <- vjj : replacement has length zero” mean and how can I solve this?

thanks a lot!


#2

Hi @anniek

Could you share a sample or dummy dataset using which we can test your code?