Exercise

# Nominal variables in R

Imagine that you surveyed several members of your family on what they think of each other. Originally, you store the names of all participants in a character vector in R, but because the information you obtained could cause disputes within the family, you decide to replace these names with arbitrarily chosen numbers. This way, no one will be able to see who said what in the survey and (hopefully) no disputes will arise.

To implement this correctly, you will have to perform an additional step. If you were to leave this numeric vector as is, R would treat it as a vector of numbers. But multiplying your grandfather and your father does not make much sense, does it? To make R treat these values as **nominal variables** instead of numbers, you should use the `factor()`

function. This function takes the name of the vector to transform and converts its elements into nominal factor variables.

In general, telling R precisely what type of variable you are working with is a good practice that can save you time and prevent careless mistakes. If you're ever unsure of what type of variable you're dealing with, you can use the `class()`

function to find out.

Instructions

**100 XP**

- Assign a vector containing the numbers
`2, 3, 5, 7, 11, 13, 17`

to the variable`participants1`

- Check the class of
`participants1`

- Transform this numeric vector to a factor vector and assign it to
`participants2`

- Check the class of
`participants2`