Basic Data Types in R
Hello friends today we will discuss about Data Types used in R. If you have little knowledge of coding or any programing language then you know that Data Types are almost common in every language. Same like that in R also we have few Data types that are use in R programming.
As we know that in programming language we need to use various variables to store various information or values. Below are the list of Data types which are used in R programming those are:
- Numeric Data Type
- Integer Data Type
- Character Data Type
- Logical Data Type
- Complex Data Type
- Raw Data Types
lets discuss them one by one with example:
Numeric Data Types:
these are basically numeric or decimal numbers which are default computational data types.
Example: 123, 245.458, 555, 12, 1.5, and so on
Programming Example:
Integer Data Type:
the data types in which numbers that do not contain decimal values have a data type as an integer. To create a integer value we have two simple ways:
use as.integer(x) :
the as.integer() function convert the numeric datatype into integer.
Example:
>int = as.integer(123)
Declare integer by appending “L”:
we can declare an integer by appending an L suffix.
>int = 53L
Programming Example:
Character Data Type:
these data type is use to represent the string value. We can also convert objects to sting by using ofas.character() function.
Example: “a”, “Hello”, “world”
Programming Example:
Logical Data Type:
The special data types which are constructed values as TRUE/FALSE are considers as Logical Data Types.
Example: True, False
Programming Example:
v <- TRUE
print(class(v))
Programming Example:
Complex Data Type:
A complex value in R is defined as the pure imaginary value i.
Example: Z=1+2i, t=7+3i
Programming Example:
v <- 2+5i
print(class(v))
Programming Example:
Raw Data Type:
A raw data type is used to holds raw bytes.
Example: "Hello" is stored as 48 65 6c 6c 6f
Programming Language:
v <- charToRaw("Hello")
print(class(v))
Programming Example:
So we learnt about R data types in this article hope you understood them.
To recap we learnt about below data types:
- Numeric Data Type
- Integer Data Type
- Character Data Type
- Logical Data Type
- Complex Data Type
- Raw Data Types
See you in next article.
Feel free to leave your comments below.
Read More:
Thank you
Well explained
ReplyDeleteSomething new to learn... well written...
ReplyDeletevery helpful
ReplyDelete