Edit the code chunks below and knit the document.
In the console, type the following:
1 + 2
a <- 1
b <- 2
a + b
Look at the Environment tab in the upper right pane. Set the variable how_many_objects
below to the number of objects listed in the environment.
how_many_objects <- 2
Use the rnorm()
function to generate 10 random values from a normal distribution with a mean of 800 and a standard deviation of 20, and store the resulting vector in the object random_vals
.
random_vals <- rnorm(10, 800, 20)
Use the help function to figure out what argument you need to set to ignore NA
values when calculating the mean of the_values
. Change the function below to store the mean of the_values
in the variable the_mean
.
the_values <- c(1,1,1,2,3,4,6,8,9,9, NA) # do not alter this line
the_mean <- mean(the_values, na.rm = TRUE)
Figure out what the function seq()
does. Use the function to set tens
to the vector c(0, 10, 20, 30, 40, 50 ,60, 70 ,80 ,90, 100)
. Set bins6
to the cutoffs if you wanted to divide the numbers 0 to 100 into 6 bins. For example, dividing 0 to 100 into 4 bins results in the cutoffs c(0, 25, 50, 75, 100)
,
tens <- seq(from = 0, to = 100, by = 10)
bins6 <- seq(0, 100, length.out = 7)
Figure out how to use the paste()
function to paste together strings with forward slashes (“/”) instead of spaces. Use paste()
to set my_dir
to “my/project/directory”.
my_dir <- paste("my", "project", "directory", sep = "/")
Install the CRAN package called “fortunes”. Run the code to do and include it in the code chunk below, but comment it out. It is bad practice to write a script that installs a package without the user having the option to cancel. Also, some packages take a long time to load, so you won’t want to install them every time you run a script.
# comment out the installation code
# install.packages("fortunes")
The code below has an error and won’t run. Fix the code.
# alternatively, you could load the library first: library(fortunes)
fortunes::fortune()
##
## Well, the biggest room in the world is the room for
## improvement :)
## -- Soren Hojsgaard ( in reply to a suggestion to make
## pbkrtest and lme4 more robust)
## R-SIG-Mixed-Models (August 2013)
Create a new project called “website”.
In the “website” project, create a new Rmarkdown document called “index.Rmd”. Do the following in this document: