Control Structures In R Programming - Study Mode
[#21] What will be the output of the following R code? > x <- 1:4
> lapply(x, runif)
Correct Answer
(A) [[1]]
[1] 0.02778712
[[2]]
[1] 0.5273108 0.8803191
[[3]]
[1] 0.37306337 0.04795913 0.13862825
[[4]]
[1] 0.3214921 0.1548316 0.1322282 0.2213059
[#22] What will be the output of the following R code? > x <- c("a", "b", "c", "d")
> for(i in 1:4) {
+ ## Print out each element of 'x'
+ print(x[i])
+ }
Correct Answer
(A) [1] "a" [1] "b" [1] "c" [1] "d"
[#23] . . . . . . . . function gives an error message if the desired package cannot be loaded.
Correct Answer
(C) Library
[#24] What will be the output of the following R code? > x <- list(a = 1:5, b = rnorm(10))
> lapply(x, mean)
Correct Answer
(A) $a [1] 3 $b [1] 0.1322028
[#25] Which of the following R code syntax is syntactically valid?
Correct Answer
(A) if ( statement1 ) {
statement2
} else if ( statement3 ) {
statement4
} else if ( statement5 ) {
statement6
} else
statement8