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 0/1

b. What is stored in x2?




 Tries 0/1

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




 Tries 0/1

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




 Tries 0/1

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




 Tries 0/1

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


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


 Tries 0/4