Create a gist now

Instantly share code, notes, and snippets.

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)))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment