Data Types in R | Beginning R Programming – Part 2

It’s really important to know your main r data types so you can check what kind of values you’re working with when modeling data, or when casting it as a certain data type. Learn how to check numeric data types from integers to floating-point numbers, negative and positive numbers, as well as character/strings and logical data types.

When working with tabled datasets it’s good to know your data types of your
atomic vectors or your variables or columns the good thing about R unlike
most other languages is that R will automatically infer the data types of
columns when reading a data set into R so you don’t need to manually tell R
the data type for every single column
but it’s really important to know your main data types
so you can check what kind of values you’re working with when
modeling data or when casting as a certain data type
So let’s first look at
your numeric types or numbers that measure things in your data
So you can get a whole number or an integer
you can get a number with a fraction or a floating-point number
A floating-point can be more than one number before or after the decimal point
Something to note when printing the result of a
floating-point number R usually rounds this up to five places after the decimal point
So it won’t just print you know an infinitely long set of numbers
after the decimal point
You can also have negative numbers
and so the same basically applies
So R classes all these kinds of numbers as one data type called numeric
So if you use the class function here
and you give it any of the numbers that we’ve mentioned
you’ll see that it’s classed it as numeric
another common data type
you’re going to often see many data sets is character
so this could be a single character
or it could be a string of characters
it could also be a number represented as a string
All these are classed as character in R so if we
use the class function again and we give it any of the string characters
you’ll see that it cast it as character
you can also use double quotation marks so that
words with apostrophes are not incorrectly interpreted as single marks
around a string so for example
“won’t” using an apostrophe
another way you can write this is to use the escape backslash
to read it as a literal apostrophe and not a quotation mark around a string
So for example…
So the datatype character can be used for text strings or unique names of
things otherwise they can be casted as factor levels or categories
later in the video series we’ll discuss the R object factor
logical or boolean data types are
also common so where there’s kind of a true or false value so the presence of
something or not so for example a variable on benign cancer might show its
values as some people to be true in having these cancer and some people to
be false in not having this cancer so if we input true or false into our class
function here
You’ll see that it properly classes it as a logical data type
And that’s it you now have an understanding of the
main datatypes you’re likely to get in your data sets
The next video we’re going to cover variables

Download the Data Set
How to Install R

Part 3: 
Creating Variables in R

Part 1:
“Hello World” Program

Full Series:
Beginning R Programming

More Data Science Material:
[Video Series] Data Mining Fundamentals
[Blog] Building Data Visualization Tools
[Blog] The Best Data Science Podcasts


Rebecca Merrett
About The Author
- Rebecca holds a bachelor’s degree of information and media from the University of Technology Sydney and a post graduate diploma in mathematics and statistics from the University of Southern Queensland. She has a background in technical writing for games dev and has written for tech publications.


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>