R Finance Tutorial - Basic Data Types

Understanding Atomic Data Types in R

Now that you're familiar with how to run commands in R, let's get a bit more technical and explore exactly what types of data you've been manipulating. There are several basic atomic data types in R, which we'll cover next.

Basic Numeric Data Types

------------------------

Numeric data are decimal numbers like 42.5. These can represent various quantities such as stock prices, cash flow, or income. Another special type of numeric data is integers, which 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 to store it as an integer. To do this, you would use the capital letter "L" after the number. For instance, 5 would be stored as an integer instead of a numeric value.

In R, you'll almost always use numeric values over integers because of this default behavior. This is nothing to worry about, so don't be concerned if you're not sure why you're seeing this difference between numeric and integer values in your data.

Character Data

----------------

Characters, also known as strings, are the text values like "hello world" or "40". Character data could represent a sequence of names, categories for your data, or even credit ratings for bonds. When giving character data to R, no quotation marks are required to indicate that you're providing it as character data. Even numbers can be stored as character data if they're enclosed in quotation marks.

Logical Data Types

--------------------

Logicals are the so-called boolean values of true and false. In R, these require that the words "true" and "false" are capitalized. For example, "True" or "False". This is necessary to distinguish logical data types from other data types.

Missing Values

----------------

Technically, an underscore ("_") can denote a missing value in R, which also happens to be a logical. However, we won't delve too deep into this topic for now.

Determining Data Type

----------------------

You've stored numeric data in variables, but you could just as easily store logical or character data in a variable as well. To determine the type of data in a variable, you can use the "class" function. For example, if we assign the word "carats" to the variable "food", and then run "class(food)", it will return "character". This is because "food" was initially assigned as character data.

Using the Class Function

-------------------------

In R, the "class" function serves as a way to view the type of data stored in a variable. It essentially allows you to see what type of data has been used for each variable. You can use this function to compare the types of numeric and integer values, such as comparing 5 with its numeric and integer versions.

For instance, if we assign both 5 and "5" to different variables, say `numeric_five` and `integer_five`, respectively, we could then run `class(numeric_five)` and `class(integer_five)`. This would display the type of data stored in each variable. In this case, it would return "numeric" for `numeric_five` and "integer" for `integer_five`.

Conclusion

----------

Now that you've learned how to determine what data types are used in R, let's move on to explore more advanced concepts. Head over to the next exercise to practice your knowledge of data types.

"WEBVTTKind: captionsLanguage: ennow that you're familiar with how to run commands in our 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 our here are the most common ones numeric data are decimal numbers like 42.5 numeric data could be a stock price 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 are that you wanted to store 5 as an integer to do this at a capital L after the number you will almost always use numerix over integers in R so this default behavior is nothing to worry about characters also called strings are the text values such as hello world or 40 character data could be a sequence of names or categories for your data or even credit ratings for bonds no two quotation marks telling are that you are giving it character data even numbers can be stored as character data if you put it in quotation marks and finally logicals are the so-called boolean values of true and false all requires that true and false are capitalized so this would cause an error technically an a to denote a missing value is also a logical but we won't go too deep into that here 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 underscore answer and the word carats is assigned to food given a variable you can use R to determine what data type it is using class using class on my underscore 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 you class to see the difference in type between a numeric and integer version of five let's find out what you learned head over to the next exercise to try out your knowledge of data typesnow that you're familiar with how to run commands in our 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 our here are the most common ones numeric data are decimal numbers like 42.5 numeric data could be a stock price 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 are that you wanted to store 5 as an integer to do this at a capital L after the number you will almost always use numerix over integers in R so this default behavior is nothing to worry about characters also called strings are the text values such as hello world or 40 character data could be a sequence of names or categories for your data or even credit ratings for bonds no two quotation marks telling are that you are giving it character data even numbers can be stored as character data if you put it in quotation marks and finally logicals are the so-called boolean values of true and false all requires that true and false are capitalized so this would cause an error technically an a to denote a missing value is also a logical but we won't go too deep into that here 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 underscore answer and the word carats is assigned to food given a variable you can use R to determine what data type it is using class using class on my underscore 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 you class to see the difference in type between a numeric and integer version of five let's find out what you learned head over to the next exercise to try out your knowledge of data types\n"