## This R script is used for the example for R Seminar in CRMDA
## This script will show how to use R script to split the Wind
## variable in the airquality data by median and then use the
## independent t-test to compare Temp between the days with high
## and low wind
## Please note that all lines can be run by clicking the menu
## command to 'Run line or selection' or use Ctrl+R.
# This function is used to find a median split of a function
MedSplit <- function(x) # New function that take a vector x.
{
med <- median(x)
n <- length(x)
group <- rep(NA, n) # Create a new variable as a result
for(i in 1:n) {
if(x[i] > med) {
group[i] <- 1
} else {
group[i] <- 2
}
}
return(group)
}
wind.degree <- MedSplit(airquality$Wind)
t.test(airquality$Temp ~ wind.degree, var.equal=TRUE)
x <- 1000
for (i in 1:20) {
x <- x - i
}