Now you know how to assign a value to a variable. Let's find out what we can assign to variables – in other words, the R data types.
In R, there are four main data types:
- Numbers;
- Strings;
- Logical values;
- Factors;
Let's consider the first two types. The first type, numbers, holds numbers in every form. We've already used 5 and 3, but we could just as easily have used 5.5 and 3.239074 (except, of course, that we would never find half or even .239074 of an animal in a zoo!)
The second data type is strings. This stores text, like "lions", "elephant", and "You're awesome". Think of it as a name or a word description of something.
Suppose you want to save the name of your favorite lion, Elsa. You would insert this text in quotes. You can use either double quotes (") or single quotes ('), but use the same at the beginning and end of the text. You would use the same operator to assign the value to a variable, like this:
my_lion <- "Elsa"