Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Factors in R

Total questions: 10

Worksheet time: 7mins

Name
Class
Date
1.

Which function of the following function is used to create factor in R

a)

factor()

b)

Factor()

c)

factors()

d)

Factors()

2.

How to check help about factor function using following command:


_factor()

(a)  

3.

What code will you run to convert following vector into Factor

sex_vector <- c("Male","Female","Female","Male","Male")

factor_sex_vector <- (a)   (sex_vector)

4.

Temperature_vector with the categories: “Low”, “Medium” and “High”.

Order:

Here it is obvious that

“Medium” stands above “Low”,

and “High” stands above “Medium”.


Which of the following is correct:

a)

factor_temperature_vector <- factor(temperature_vector, order = TRUE, levels = c("Low", "Medium", "High"))

b)

factor_temperature_vector <- factor(temperature_vector, order = TRUE, levels = c("High", "Medium", "Low"))

5.

survey_vector <- c("M", "F", "F", "M", "M")

factor_survey_vector <- factor(survey_vector)

Command to convert M to Male and F to Female in factor_survey_vector

a)

factor(survey_vector)

b)

levels(factor_survey_vector) <-c("Female","Male")

c)

level(factor_survey_vector) <-c("Male","Female")

d)

levels(factor_survey_vector) <-c("Male","Female")

6.

Generate summary for factor_survey_vector

(a)   (factor_survey_vector)


Output:

## Female Male

## 2 3

7.

# Consider unordered factor

factor_speed_vector


## [1] medium slow slow medium fast

## Levels: fast medium slow


# What might be output of the following statement

factor_speed_vector[1] > factor_speed_vector[2]

a)

TRUE

b)

FALSE

c)

not meaningful for factor

d)

EQUAL

8.

# Consider ordered factor

factor_speed_vector


## [1] medium slow slow medium fast

## Levels: slow < medium < fast


# What might be output of the following statement

factor_speed_vector[1] > factor_speed_vector[2]

a)

TRUE

b)

FALSE

c)

not meaningful for factor

d)

EQUAL

9.

# Convert speed_vector into ordered factor such that

# slow < medium < fast

speed_vector <- c("medium", "slow", "slow", "medium", "fast")

Complete the follwoing command:

factor_speed_vector <- factor(speed_vector, ordered = ____, levels = c("slow", "medium", "fast"))

a)

TRUE

b)

FALSE

c)

True

d)

False

10.

# Convert speed_vector into ordered factor such that

# slow < medium < fast


Complete the following command:

factor_speed_vector <- factor(speed_vector, ordered = TRUE, levels = c("____", "______","____")

a)

slow

b)

medium

c)

fast

d)

low

e)

high