Filling your Data Holes

So today I was working on filling out some data holes with zeros. I wrote this…


FillDataHolesWithZeros = function(input){
countZero = input %>%
group_by(Ticket.Created.Date...Time) %>%
summarise(count = n()) %>%
filter(count < length(levels(input$Case.Owner))) for(i in 1:nrow(countZero)) { date = countZero[i,]$Ticket.Created.Date...Time departments = input %>% filter(Ticket.Created.Date...Time == date)
myLevels = levels(input$Case.Owner)
for(j in 1:nrow(departments))
{
owner = departments[j,]$Case.Owner
myLevels = myLevels[myLevels != owner]
}
print(paste(i,":",myLevels))
for(k in 1:length(myLevels)){
input = input %>% rbind(data.frame(
Ticket.Created.Date...Time = date,
Case.Owner = myLevels[k],
count = 0
))
}
}
return(input)
}

Which ends up in R can be done very generically with this:

data %>% complete(Case.Owner, fill = list(count = 0))

There you go a trick of the day!

Leave a Reply

Your email address will not be published. Required fields are marked *