Rewrite each code block to comply with the class style guide.
x < - c( 1,-2,3,-4,5,NA ) y < - x * - 1 y[ y>0 ]
n = 1 mycondition <- round (runif (1,0,1,)) if( mycondition ) { n <- n + 1 print(paste("n =" , n , sep=" ")) } else { print("false") }
# create a sequence from 1 to 50 z <- seq(1,50) # test whether an observation is even even <- z%%2 = = 0 # subset z by the test above z = z [even] # plot a histogram library( ggplot2 ) qplot (z, geom="histogram", binwidth=1)
mat <- matrix( c( 34, 23, 53, 6, 78, 93, 12, 41, 99 ) ,nrow = 3) df <- as.data.frame (mat) names( df ) <- c("score_given_to_car_on_driving_test", "score.given.to.van.on.driving.test", "score-given-to-truck-on-driving-test")
library( ggplot2 ) head(mpg) second_version_of_mpg <- mpg[ mpg$cyl = 6,] second_version_of_mpg$class <- as.character(mpg2$class) qplot(cty, hwy, data=second_version_of_mpg, geom="point", color=class ) + geom_smooth( method = "lm", se=FALSE ) + opts (title="City vs. Highway MPG" )
mean <- function(x) { sum(x)/length(x) }