R-Studio Commands Quiz 1 Operations · Addition · Subtraction · Multiplication · Division "/" · Powers Variables . You can store a value in a variable using the assignment operator, =, such as > myvalue = 42 > myvalue*myvalue [1] 1764 . You can enter small lists using the c () notation, such as > heights = c(174,160, 169, 166, 182, 153, 191, 162) > heights [1] 174 160 169 166 182 153 191 162 Functions . The R language is built around functions, particularly for manipulating data and doing more complex calculations. · These functions include; o Length of a List "length ()" o Mean "mean ()" o Median "median ()" Standard Deviation "sd ()" o IQR "IQR ()" o Exponentials "exp ()" o Logarithms "log ()"
> mean (heights) [1] 169.625 > median (heights) [1] 167.5 > sd(heights) [1] 12.36282 > IQR(heights) [1] 14.5 . Most R functions have options you can add to alter function's behaviour, such as > log(100, base=10) [1] 2 Help · A useful function is help (). For example, help (log) will give you information about the log function. Quiz 2 Opening a CSV file · When Looking at the Data Summary Statistics Tell me something you haven't told anyone else ... please don't go Additional
Commands for Conducting a Two-sample T-test cola = read.csv("Alice.csv") cola$Change = cola$After - cola$Before bwplot (Change ~ Caffeine, data=cola) aggregate(Change ~ Caffeine, data=cola, mean) t. test(Change ~ Caffeine, data=cola, alternative="greater") *Change and Caffeine were variables Commands for Conducting Linear Regression oxy = read. csv("Oxytocin. csv") xyplot(Basal ~ Age, data=oxy, type=c("p", "r") ) oxylm = Im(Basal ~ Age, data=oxy) summary(oxylm) # use plot() to see the diagnostic plots for the model plot(oxylm) Commands for Conducting a One-Way ANOVA fans = read. csv("Transpiration.csv") bwplot (WaterLoss ~ WindSpeed, data=fans) aggregate(WaterLoss ~ WindSpeed, data=fans, mean) summary(aov(WaterLoss ~ WindSpeed, data=fans)) Here is how to make a plot of means with error bars. This uses the ddply function from the plyr library to first create a new data frame with the summary statistics and interval bounds. library(lattice) library(plyr) data = ddply(fans, c("WindSpeed"), summarise, n = length (WaterLoss), mean = mean(WaterLoss), sd = sd(WaterLoss), se = sd / sqrt(n)) data$ulim = data$mean + data$se data$11im = data$mean - data$se stripplot(data$mean ~ data$WindSpeed, xlab = "Wind Speed", ylab = "Water Loss (mL)", ylim = c(0,8), panel = function(x, y, ... , subscripts) { panel. segments(x, data$1lim[subscripts], x, data$ulim[subscripts]); panel.xyplot(x, y, subscripts = subscripts, ... , pch=16) 1 Commands for Conducting a Multiple Regression Analysis Commands for Conducting a Chi-Squared Test Commands for Conducting a Two-Way ANOVA Commands for Conducting a Logistic Regression