Install R: Find the download link here
Install RStudio: Find the appropriate download link here
Learn how to use Rstudio: An opinionated tour of RStudio
ans_1a_x
and set its value to
10
, a variable named ans_1a_y
and set its
value to 5
, and a variable named ans_1a_z
and
set its value to the sum of ans_1a_x
and
ans_1a_y
. The line of code that you write to define
ans_1a_z
must include the +
operator.ans_1b_x
and set its value to
"10"
, a variable named ans_1b_y
and set its
value to "5"
, and a variable named ans_1b_z
and set its value to the sum of the numeric values of
ans_1b_x
and ans_1b_y
. The line of code that
you write to define ans_1b_z
must include the
+
operator and the as.numeric()
function.ans_1c
and set its value to the
logical
result indicating if ans_1a_x
is equal
to ans_1a_y
. The line of code that you write to define
ans_1c
must include the ==
operator.vector
named ans_2a
that contains
the elements 2
, 3
, 5
,
7
, and 11
.list
named ans_2b
that contains
the elements 1
, 2
, "a"
,
"b"
and TRUE
.data.frame
named ans_2c
that
contains v1
, v2
, and v3
as
defined below as columns. Make sure the column names of the
data.frame
you create are equal to the variable names
v1
, v2
, and v3
.v1 <- c('I', 'I', 'I', 'I', 'II', 'II', 'II', 'II')
v2 <- c('a', 'a', 'b', 'b', 'c', 'c', 'd', 'd')
v3 <- c(-1.6297880,
-1.0738506,
0.0299236,
-1.5435811,
-0.5133278,
-1.4716107,
-1.1986316,
-1.5548207)
vector
named tmp
defined in the following code
chunk and store the result in a variable named ans_3a
.tmp <- c(0.24, 0.015, 1.34, -1.00, -0.15)
list
named tmp
defined in the following code
chunk and store the result in a variable named ans_3b
. Be
sure that the data type of ans_3b
is
character
.tmp <- list(0.5, "W", FALSE)
v2
from the data.frame
named tmp
defined in the
following code chunk and store the result in a variable named
ans_3c
. Be sure that the line of code that you write
includes the $
operator.tmp <- data.frame(v1=c(1, 2, 3),
v2=c('A', 'B', 'C'),
v3=c(TRUE, TRUE, FALSE))
tmp
? Store your answer in a variable named
ans_4a
by copying, pasting, and uncommenting one of the
commented out lines of code below.element_1 <- "A"
element_2 <- 2
element_3 <- FALSE
tmp <- list(element_1, element_2, element_3)
# ans_4a <- "character"
# ans_4a <- "numeric"
# ans_4a <- "logical"
tmp
? Store your answer in a variable named
ans_4b
by copying, pasting, and uncommenting one of the
commented out lines of code below.element_1 <- "A"
element_2 <- 2
element_3 <- FALSE
tmp <- c(element_1, element_2, element_3)
# ans_4b <- "character"
# ans_4b <- "numeric"
# ans_4b <- "logical"
x <- 5
for(i in c(1, 3, 5)) {
x <- i + 2
}
What is the value of x
after the loop has finished
executing?
What is the value of i
after the loop has finished
executing?
Modify the code chunk such that the final value of x
is 10 and i
is 20.
x <- 10
y <- c(1, 2, 3)
while(x > 5) {
y <- c(x, y)
x <- x - 1
}
How many elements does y
contain after the loop has
finished?
What is the value of the final element in y
and can
you figure this out without executing the code?
if(x > y) {
z <- 10
} else {
z <- 2
}
What is the value of z
if x <- 10
and y <- -10
What is the value of z
if x <- -5
and y <- 5
What is the value of z
if x <- 0
and
y <- 0
for(i in 1:10) {
x <- i * 2
if(x > 5) {
break
}
}
How many times will this loop run?
What is the value of i
and x
when the
loop stops?
if(x == y) {
z <- 1
} else if(x > y) {
z <- 2
} else if(x < y) {
z <- 3
}
z
if x <- 10
and
y <- -10
z
if x <- -5
and
y <- 5
z
if x <- 0
and
y <- 0
f <- function(x) {
y <- x^2
return(y)
}
z <- f(3)
What are the values of x
, y
and
z
?
f <- function(x) {
y <- x^2
return(y)
}
g <- function(x) {
y <- x - 2
return(y)
}
z <- f(g(4))
What are the values of x
, y
and
z
?
f <- function(x, y, z) {
res <- x + y - z
return(res)
}
f(2, 1, -4)
a valid way to call the function
f
?f(y=2, 1, -4)
a valid way to call the function
f
?f(y=2, 1, -4)
a wise way to call the
function f
?f
?