#Renaming variable names names(NYC_Trees)[5] names(NYC_Trees)[5] <- "Diameter" names(NYC_Trees)[6] <- "Height" names(NYC_Trees)[9] <- "CanopyArea" #Basic Summary Statistics #Measures of location mean(NYC_Trees$Height) median(NYC_Trees$Height) min(NYC_Trees$Height) max(NYC_Trees$Height) #Working with quantiles quantile(NYC_Trees$Height) quantile(NYC_Trees$Height,c(0.10,0.90)) #Specifing additional quantiles whichones <- seq(0,1,by=0.05) quantile(NYC_Trees$Height, whichones) #Creating a Cumulative Density Plot of Height plot(quantile(NYC_Trees$Height, whichones),whichones,xlab="Height",ylab="Percentiles") lines(quantile(NYC_Trees$Height, whichones),whichones) ######################################### #Measures of spread sd(NYC_Trees$Height) range(NYC_Trees$Height) mad(NYC_Trees$Height) library(lsr) aad(NYC_Trees$Height) #Getting the mean absolute deviation via brute force mean.vector <- rep(mean(NYC_Trees$Height),319) deviation<-NYC_Trees$Height - mean.vector abs.deviation<-abs(deviation) mean(abs.deviation) View(data.frame(Height=NYC_Trees$Height[1:10],mean.vector=mean.vector[1:10],deviation=deviation[1:10],abs.deviation=abs.deviation[1:10])) table(NYC_Trees$Condition) table(NYC_Trees$Condition) / length(NYC_Trees$Condition) 100 * table(NYC_Trees$Condition) / length(NYC_Trees$Condition) round(100 * table(NYC_Trees$Condition) / length(NYC_Trees$Condition),1) table(NYC_Trees$Native, NYC_Trees$Condition) plot(table(NYC_Trees$Native, NYC_Trees$Condition)) native.condition.table <- table(NYC_Trees$Native, NYC_Trees$Condition) margin.table(native.condition.table,1) margin.table(native.condition.table,2) prop.table(native.condition.table,1) prop.table(native.condition.table,2) mean(NYC_Trees$Diameter);mean(NYC_Trees$Height);mean(NYC_Trees$Age);mean(NYC_Trees$PercentFoliageDensity);mean(NYC_Trees$CanopyArea);mean(NYC_Trees$CompensatoryValue) apply(NYC_Trees[,5:10],2,function(x){sd(x)/mean(x)}) apply(NYC_Trees[,5:10],2,mean) apply(NYC_Trees[,5:10],2,mean) colMeans(NYC_Trees[,5:10]) aggregate(NYC_Trees[,5:10],by=list(NYC_Trees$Native),mean) aggregate(NYC_Trees[,5:10],by=list(NYC_Trees$Condition,NYC_Trees$Native),mean)