r <- c(2,4,6,8,9)
s <- c(1,3,5,7,9)
print(r*s)
## [1] 2 12 30 56 81
print(r^s)
## [1] 2 64 7776 2097152 387420489
print(r%%s)
## [1] 0 1 1 1 0
t <- 1
while (t<12) {
print ("t")
t=t+1
}
## [1] "t"
## [1] "t"
## [1] "t"
## [1] "t"
## [1] "t"
## [1] "t"
## [1] "t"
## [1] "t"
## [1] "t"
## [1] "t"
## [1] "t"
vecna <- 1:10
for(i in vecna)
print(i)
## [1] 1
## [1] 2
## [1] 3
## [1] 4
## [1] 5
## [1] 6
## [1] 7
## [1] 8
## [1] 9
## [1] 10
seqna <- seq(0,6)
print(seqna)
## [1] 0 1 2 3 4 5 6
print(max(seqna))
## [1] 6
print(min(seqna))
## [1] 0
mike <- c(1,1,2,3,5,5,6,6,6,7,9)
print(mean(mike))
## [1] 4.636364
print(median(mike))
## [1] 5
getmode <- function(mike){
unimike <- unique(mike)
unimike[which.max(tabulate(match(mike,unimike)))]
}
print(getmode(mike))
## [1] 6
x <- c(15,17,18,20,21,24,26,29)
y <- c(73.4,74.5,75.8,77.2,79.1,78.8,80.4,81.1)
relation <- lm(y~x)
print(relation)
##
## Call:
## lm(formula = y ~ x)
##
## Coefficients:
## (Intercept) x
## 65.6635 0.5588
print(summary(relation))
##
## Call:
## lm(formula = y ~ x)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.76803 -0.64953 -0.09781 0.24647 1.70219
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 65.66348 1.50507 43.628 9.71e-09 ***
## x 0.55878 0.06931 8.062 0.000195 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.8754 on 6 degrees of freedom
## Multiple R-squared: 0.9155, Adjusted R-squared: 0.9014
## F-statistic: 64.99 on 1 and 6 DF, p-value: 0.000195
a <- data.frame(x=19)
print(predict(relation,a))
## 1
## 76.28025
plot(x, y,
main = "Regression Line: y vs x",
xlab = "x values",
ylab = "y values",
pch = 16, col = "blue")
abline(relation, col = "red", lwd = 2)
# Question 7
pumpkin <- c(8,4,7,9,1,5)
lbls <- c("Older", "Younger", "Mom", "Dad", "Baby", "Middle")
pie(pumpkin, labels = lbls, main="Family Pumpkin Pie Chart")
# Question 8
data(mtcars)
boxplot(disp ~ gear, data = mtcars,
main = "Displacement by Gear",
xlab = "Gear",
ylab = "Displacement")