setwd("~/Courses/R_peterson/week_seven")
coral<-read.csv("coral.csv")
weath<-read.csv("weather.csv")
coral$Date<-as.Date(coral$Date, format = "%d-%b-%Y")
coral$year<-as.numeric(format(coral$Date, format ="%Y"))
cor_weat<-merge(coral, weath, all = T, by=c("year", "quadrat") )
The files are read in and merged
cor_weat$year<-as.character(cor_weat$year)
cor_weat$quadrat<-as.character(cor_weat$quadrat)
cor_weat_2<-cor_weat
summ_stats<-function(cor_weat_2,fle.name){
sum.table<- c()
rnames<-c()
z<-ncol(cor_weat_2)
for(i in 1:z){
if(is.numeric(cor_weat_2[,i])) sum.table<- rbind(sum.table,c(mean(cor_weat_2[,i]),sd(cor_weat_2[,i]),
min(cor_weat_2[,i]),max(cor_weat_2[,i])))
if(is.numeric(cor_weat_2[,i])) rnames<-c(rnames,colnames(cor_weat_2)[i])
###unable to get the row names to reflect the numeric columns.
#How do I build into my loop the renaming of rows and columns?
}
row.names(sum.table)<-c(rnames)
sum.table<-as.data.frame(sum.table)
colnames(sum.table)<- c("Mean", "SD", "Min", "Max")
write.csv(sum.table,fle.name)
return(sum.table)
}
This also saves the output as a csv
Mean SD Min Max
percent_cover 49.722296 25.346430 4.00 95.00
colony_size 181.974633 103.797227 0.00 355.00
wind 6.392523 3.441373 1.00 12.00
temperature 27.497183 1.141181 25.34 29.64