Homework 1

Practicing my incorporation of R code into an HTML page


round(sqrt(18), digits=0) #I am proud of this attempt!
## [1] 4

Now, the same formula, but with the R hidden

## [1] 4

Calculating mean and median

Next, Chad showed me that to calculate a mean from a set of numbers, I have to concantenate (“link things together in a chain or series”) like this:

a<-c(1:10)

In this code, c means concantenate, so this produces the numbers from 1 to 10.

Then I can say “mean(a)” like this:

a<-c(1:10)
mean(a)
## [1] 5.5

Likewise, if I want to calculate the mean of a set of non-sequential numbers, I can say

b<-c(1,12,17)

Then “mean(b)” like this:

b<-c(1,12,17)
mean(b)
## [1] 10

What about calculating the median? I try:

b<-c(1,12,17)

then “median(b)”" like this:

b<-c(1,12,17)
median(b)
## [1] 12


Tips