R Tutorial : Basic Data Types
Skills:
Data Literacy60%
Key Takeaways
Introduction to basic data types in R, including numeric, integer, character, and logical data types, as well as the use of functions such as class() to determine data type.
Full Transcript
now 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 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 our 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 present it to you as output you use 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
Original Description
Want to learn more? Take the full course at https://learn.datacamp.com/courses/introduction-to-r-for-finance at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
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.
Numeric data are decimal numbers like 42.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.
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, 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 logical, but we won't go 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_answer and the word "carrots" is assigned to food.
Given a variable, you can use R to determine what data type it is with 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 a
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from DataCamp · DataCamp · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
SQL Server Tutorial: Date manipulation
DataCamp
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
R Tutorial: Adding aesthetics to represent a variable
DataCamp
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
Python Tutorial: Preparation for modeling
DataCamp
Python Tutorial: Machine Learning modeling steps
DataCamp
R Tutorial: The prior model
DataCamp
R Tutorial: Data & the likelihood
DataCamp
R Tutorial: The posterior model
DataCamp
R Tutorial: An Introduction to plotly
DataCamp
R Tutorial: Plotting a single variable
DataCamp
R Tutorial: Bivariate graphics
DataCamp
Python Tutorial: Customer Segmentation in Python
DataCamp
Python Tutorial: Time cohorts
DataCamp
Python Tutorial: Calculate cohort metrics
DataCamp
Python Tutorial: Cohort analysis visualization
DataCamp
R Tutorial: Building Dashboards with flexdashboard
DataCamp
R Tutorial: Anatomy of a flexdashboard
DataCamp
R Tutorial: Layout basics
DataCamp
R Tutorial: Advanced layouts
DataCamp
Python Tutorial: Time Series Analysis in Python
DataCamp
Python Tutorial: Correlation of Two Time Series
DataCamp
Python Tutorial: Simple Linear Regressions
DataCamp
Python Tutorial: Autocorrelation
DataCamp
R Tutorial: The gapminder dataset
DataCamp
R Tutorial: The filter verb
DataCamp
R Tutorial: The arrange verb
DataCamp
R Tutorial: The mutate verb
DataCamp
R Tutorial: What is cluster analysis?
DataCamp
R Tutorial: Distance between two observations
DataCamp
R Tutorial: The importance of scale
DataCamp
R Tutorial: Measuring distance for categorical data
DataCamp
Python Tutorial: Plotting multiple graphs
DataCamp
Python Tutorial: Customizing axes
DataCamp
Python Tutorial: Legends, annotations, & styles
DataCamp
Python Tutorial: Introduction to iterators
DataCamp
Python Tutorial: Playing with iterators
DataCamp
Python Tutorial: Using iterators to load large files into memory
DataCamp
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
SQL Tutorial: Tables: At the core of every database
DataCamp
SQL Tutorial: Update your database as the structure changes
DataCamp
Python Tutorial: Classification-Tree Learning
DataCamp
Python Tutorial: Decision-Tree for Classification
DataCamp
Python Tutorial: Decision-Tree for Regression
DataCamp
Python Tutorial: Census Subject Tables
DataCamp
Python Tutorial: Census Geography
DataCamp
Python Tutorial: Using the Census API
DataCamp
R Tutorial: A/B Testing in R
DataCamp
R Tutorial: Baseline Conversion Rates
DataCamp
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
R Tutorial: Introduction to qualitative data
DataCamp
R Tutorial: Understanding your qualitative variables
DataCamp
R Tutorial: Making Better Plots
DataCamp
SQL Tutorial: OLTP and OLAP
DataCamp
SQL Tutorial: Storing data
DataCamp
SQL Tutorial: Database design
DataCamp
Python Tutorial: Introduction to spaCy
DataCamp
Python Tutorial: Statistical Models
DataCamp
Python Tutorial: Rule-based Matching
DataCamp
More on: Data Literacy
View skill →
🎓
Tutor Explanation
DeepCamp AI