Browsing resource, all submissions are temporary.
Tip: Always check your answers by typing the commands in R before submission.
Suppose I type the following R commands:
x1 <- rep(c("red","green","blue"),3)
x2 <- rep(c("red","green","blue"),each=3)
a. What is stored in x1? A character vector containing '"red" "green" "blue" "blue" "green" "red" "red" "green" "blue"' and in that order A character vector containing '"red" "red" "red" "green" "green" "green" "blue" "blue" "blue"' and in that order A character vector containing '"red" "green" "blue" "red" "green" "blue" "red" "green" "blue"' and in that order none of the above
x1
b. What is stored in x2? A character vector containing '"red" "green" "blue" "red" "green" "blue" "red" "green" "blue"' and in that order A character vector containing '"red" "green" "blue" "blue" "green" "red" "red" "green" "blue"' and in that order A character vector containing '"red" "red" "red" "green" "green" "green" "blue" "blue" "blue"' and in that order none of the above
x2
c. In the expression y1 <- as.factor(x1). What is stored in y1? A character vector containing '"red" "green" "blue" "red" "green" "blue" "red" "green" "blue"' A factor vector containing '"red" "red" "red" "green" "green" "green" "blue" "blue" "blue"' with 3 levels: red, green and blue A factor vector containing 'red green blue red green blue red green blue' with 3 levels: blue, green and red none of the above
y1 <- as.factor(x1)
y1
d. In the expression y2 <- factor(x1,levels=c("red","green","blue")), what is stored in y2? A factor vector containing 'red green blue red green blue red green blue' with 3 levels: red, green and blue A character vector containing '"red" "green" "blue" "red" "green" "blue" "red" "green" "blue"' A factor vector containing '"red" "red" "red" "green" "green" "green" "blue" "blue" "blue"' with 3 levels: red, green and blue none of the above
y2 <- factor(x1,levels=c("red","green","blue"))
y2
e. In the expression y3 <- factor(x1,levels=c("black","red","green","blue")), what is stored in y3? A factor vector containing 'red green blue red green blue red green blue' with 3 levels: red, green and blue A character vector containing '"red" "green" "blue" "red" "green" "blue" "red" "green" "blue"' A factor vector containing 'red green blue red green blue red green blue' with 4 levels: black, red, green and blue none of the above
y3 <- factor(x1,levels=c("black","red","green","blue"))
f. The function as.integer() is applied to the variables x1, y1, y2 and y3. Match the following outputs to the commands.
as.integer()
y3
3 2 1 3 2 1 3 2 1
NA NA NA NA NA NA NA NA NA
2 3 4 2 3 4 2 3 4
1 2 3 1 2 3 1 2 3