# # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- DF = read.csv("../../Data/table_1_5.csv") males = DF$Sex=="M" females = DF$Sex=="F" # Compute statistics of the numerical variables by sex: # df_M = DF[males,] m_min = apply( df_M[,c(-1,-2)], 2, min ) m_median = apply( df_M[,c(-1,-2)], 2, median ) m_max = apply( df_M[,c(-1,-2)], 2, max ) df_F = DF[females,] f_min = apply( df_F[,c(-1,-2)], 2, min ) f_median = apply( df_F[,c(-1,-2)], 2, median ) f_max = apply( df_F[,c(-1,-2)], 2, max ) # Group statistics by sex and print: # summary_DF_male = data.frame( rbind( m_min, m_median, m_max ) ) rownames(summary_DF_male) = c( "min", "median", "max" ) summary_DF_female = data.frame( rbind( f_min, f_median, f_max ) ) rownames(summary_DF_female) = c( "min", "median", "max" ) print(summary_DF_male) print(summary_DF_female) n_males = sum(males) n_females = sum(females) color = rep( "red", n_males+n_females ) color[males] = "blue" #postscript("../../WriteUp/Graphics/Chapter1/ex_6_scatter_plot.eps", onefile=FALSE, horizontal=FALSE) par(mfrow=c(1,2)) plot( DF$Age, DF$Height, col=color, pch=20, cex=1.5, xlab='Age', ylab='Height' ) grid() plot( DF$Age, DF$Weight, col=color, pch=20, cex=1.5, xlab='Age', ylab='Weight' ) grid() par(mfrow=c(1,1)) #dev.off()