MattSandy
4/4/2016 - 8:28 PM

Calculate percentage of occurrences for diseases based on the herd and date.

Calculate percentage of occurrences for diseases based on the herd and date.

df <- read.csv(paste("~/R/df/","import.csv",sep=""),
                 header = TRUE, sep = ",", quote = "\"",stringsAsFactors = FALSE, encoding="UTF-8")
names(df) <- c("herd","date","disease")
output <- matrix(, nrow = 0, ncol = 4)
for(herd in unique(df$herd)) {
    for(date in unique(df$date)) {
        for(disease in unique(df$disease)) {
            subset <- df[which(df$herd==herd & df$date==date),]
            output <- rbind(output,c(herd,date,disease,nrow(subset[which(subset$disease==disease),])/nrow(subset)))
        }
    }
}