1. LON-CAPA Logo
  2. Help
  3. Log In
 

Browsing resource, all submissions are temporary.


Factor Variables

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?




 Tries [_1]

b. What is stored in x2?




 Tries [_1]

c. In the expression y1 <- as.factor(x1). What is stored in y1?




 Tries [_1]

d. In the expression y2 <- factor(x1,levels=c("red","green","blue")), what is stored in y2?




 Tries [_1]

e. In the expression y3 <- factor(x1,levels=c("black","red","green","blue")), what is stored in y3?




 Tries [_1]

f. The function as.integer() is applied to the variables x1, y1, y2 and y3. Match the following outputs to the commands.


1 2 3 1 2 3 1 2 3


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


 Tries [_1]