Problem 1
Problem 1, 6
Problem 4
Problem 2
Problem 1 (scan your drawing and link it with your .Rmd file)
Problem 2, 3
Problem 2
Problem 3
Problem 1
Problem 1
Problem 3
Problem 3
Problem 2
Problem 2
(Data manipulation)
data(iris)
swidth.versicolor <- NULL
for (i in seq_len(nrow(iris)) ) {
if (iris$Species[i]=="versicolor") {
swidth.versicolor <- c(swidth.versicolor, iris$Sepal.Width[i])
}
}
Vectorize the above code.
data(iris)
head(iris$Sepal.Length[iris$Species])
Explain why you get those results.
(Closure) Simply speaking, a closure is a function created by another function.
power <- function(exponent) {
function(x) {
x ^ exponent
}
}
square <- power(2)
square(2)
square(4)
cube <- power(3)
cube(2)
cube(4)
k()
will return? Explain. j <- function(x) {
y <- 2
function() {
c(x, y)
}
}
k <- j(1)