R Questions
R Questions
1- Given the below matrix, what changes would the following command generate
iMatrix[1,]<-c(1, 2, 3)
4 5 2 1
(7 1 6 4)
8 3 2 6
a. The first three values of the first column would change into the values within the
vector.
b. The first three values of the first row would change into the values within the
vector.
c. The first three values of the first row would be added to the values within the
vector.
d. None of the above
Answer: d
Answer: d
Answer: a
4- Which of the following code does not identify if a given number is positive or negative
or zero?
a. x <- 0
if (x < 0) {
print("Negative number")
} else if (x > 0) {
print("Positive number")
} else
print("Zero")
b. if (x < 0) {
print("Negative number")
}
else if (x > 0) {
print("Positive number")
}
else (x == 0) {
print("Zero")
}
c. if (x < 0) {
print("Negative number")
else if (x > 0) {
print("Positive number")
else
print("Zero")
}
}
d. if (x < 0) {
print("Negative number")
if (x > 0) {
print("Positive number")
if (x==0){
print("Zero")
}
}
}
Answer: a
a. X & X, X | Y, Y & Z
b. X & Z, X & Y, Y | Z
c. X & Z, Z | Y, Y | Z
d. Z & X, Z | Z, X & X
Answer: c
Answer: d
7- Which of the following functions produce the same results as the function below?
f <- function(x) {
for(i in 1:x) {
y <- i^2
print(y)
}
}
f(3)
a. f <- function() {
for(i in 1:2) {
print(i^2)
}
}
f()
b. f <- function() {
for(i in 1:5) {
print(i^2)
}
}
f()
c. f <- function() {
for(i in 1:3) {
print(i^2)
}
}
f()
d. f <- function(a) {
for(i in 1:5) {
print(i^2)
}
}
f()
Answer: c
8- Write a function to specify the exponent using the second argument directly, Sets the
default of the exponent to 3.
Answer: c
Answer:b