### Set my working directory setwd("~/Desktop/Teaching/CompGenWS-GEN8900/") ### Read in the my functions file library(devtools) source_gist("c954c757db02eb6c4ccfae1aa090658c", filename="compGen17_fxns.R", quiet=TRUE) ### Read in the sample data file my.data = read.vcf("SampleData/sampleData_Tajima.vcf", header=TRUE, stringsAsFactors=FALSE) ### Divide the data into windows, and set up ### a results table my.win=seq(min(my.data$POS), max(my.data$POS), by=600) # This command gets all of the window Start positions my.results=data.frame(Start=my.win, End=(my.win+600), SNPs=rep(0, length(my.win))) # By adding 600 to every Start, I get all of the Window End positions ### Calculate the number of SNPs in each window for (i in 1:nrow(my.results)) { # Notice here that the number of iterations in my loop is equal to the number of rows in my RESULTS, not my input data d=subset(my.data, (my.data$POS>=my.results$Start[i] & my.data$POS=my.results$Start[i] & my.data$POS