1. Basic data types
Now that you're familiar with how to run commands in R, let's get a bit more technical into exactly what types of data you have been manipulating. There are a number of basic atomic data types in R. Here are the most common ones.
2. Numeric
Numeric data are decimal numbers like 42-point-5. Numeric data could be stock prices, cash flow, or income. A special type of numeric data is integers. Integers are whole numbers that do not have a decimal place. By default, whole numbers like 5 are stored as numeric data unless you specifically tell R that you want it to store 5 as an integer. To do this, add a capital L after the number. You will almost always use numerics over integers in R, so this default behavior is nothing to worry about.
3. Character
Characters, also called strings, are text values such as "Hello world", or "forty". Character data could be a sequence of names, or categories for your data, or even credit rating for bonds. Note the quotation marks telling R that you are giving it character data. Even numbers can be stored as character data if you put it in quotation marks. And finally,
4. Logical
Logicals are the so called boolean values of TRUE and FALSE. R requires that true and false be capitalized, so this would cause an error. Technically, NA, to denote a missing value, is also a logical, but we won't go deep into that here.
5. Variables and data types
So far, you have stored numeric data in variables, but you could have just as easily stored logical or character data in a variable as well. Here, the logical TRUE is assigned to my_answer and the word "carrots" is assigned to food. Given a variable, you can use R to determine what data type it is with
6. class()
class. Using class on my_answer returns "logical", telling you that the my_answer variable contains a logical data type. class is what is known as a function. You will see a number of useful functions throughout the course, but for now, you can think of them as a black box, where you pass in some kind of input, the function calculates some value, and presents it to you as output. You can use class to see the difference in type between the numeric and integer versions of 5.
7. Let's practice!
Let's find out what you learned, head over to the next exercise to try out your knowledge of data types.