#Load the appropriate libraries library(DBI); library (RMySQL); library (lattice); #Establish the connection to the database drv<-dbDriver("MySQL"); con<-dbConnect( drv, username="jadler", password="P@ssw0rd", dbname="bbdatabank",host="localhost"); #Build the data set res<-dbSendQuery(con, "select * from batting where yearID=2003 and AB > 250"); batting2003<-fetch(res, n=-1); attach(batting2003); #Compute batting averages AVG<-H/AB; #Plot the charts histogram(~ AVG | teamID), nint=10 densityplot(~ AVG | teamID), plot.points=FALSE