Created
April 4, 2016 20:28
-
-
Save MattSandy/3a87b59ea354edb4e16f83874187ff5a to your computer and use it in GitHub Desktop.
Calculate percentage of occurrences for diseases based on the herd and date.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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