Introduction To R Data Types
For any programming language, data type plays an important role. The programming language also contains variables that store different data types. And each data type can perform different tasks. R also contains data types and variables. In the R programming language, you don’t have to declare variables with any particular data type. We can also change the type even after it has been set.
Table of contents
Types of R Programming Language
R programming language consists of five basic data types:
- Character
- Numeric (real or decimal)
- Integer
- Logical
- Complex
1. Character data type: It stores characters as their values or strings. In the R programming language, strings have an alphabet, numbers, and symbols.
2. Numerical data type: It stores numeric values. It is a default data type in the R programming language.
Example: 2, 65.9, 89 0.0001
3. Integer data type: This data type stores integer values. You will have to specify a number as an integer to store. It is only used for values like unique ids.
You can store and convert a value into an integer using the below for format:
Example: as.integer()function
4. Logical data type: This type of data type stores Boolean or logical values. It stores values of True or False.
5. Complex data type: It stores numbers with an imaginary component.
Example: 2 6i, -14 3i
What Is Vector?
In the R programming language, it is the most basic data structures.
It is of two types:
- Atomic vectors
- Lists
Types of vector modes:
- Character
- Logical
- Integer
- Numeric
With the help of Vector, you can also create an empty vector like vector().
What Do You Understand By Factor Datatype?
- In the R programming language, factors are considered as variables that take a limited number of different values. The most crucial use of factors is in statistical modeling. It is because categorical variables have a different take on in statistical models than continuous variables.
- It is stored as a vector integer values. You can make use of the factor function to create a factor. You can make numeric and character variables into factors. And the factor’s level will always have character values. In factors, character values are stored efficiently. It is because each unique character value is stored only once.
What Is List Data Type?
The list data type has a countable number of values in which the same value can appear for more than once. The list is used for different data structures. It will help in implementing abstract lists like arrays and linked lists. There are several programming languages that support the feature of list data types. It has different syntax and semantics for lists and list of operations.
Listed below are the three types of list data type:
- List – string: It can store text values till 255 characters.
- List – numbers: It can store numeric values till 15 digits.
- List – date: It can store date and time values.
In each List data type, till 1,000 values can be defined and can be stored.
In List data type, duplicate and blank values are automatically deleted whenever you save table design. If you are changing the values of lists, it will not affect the values in existing records.
Know about Matrix:
In the R programming language, Matrix is considered as a data type that has the dimension – the rows and the columns. It consists of elements that have the same class type. You can declare an integer, character and also complex elements. You cannot declare modes/class elements such as integer and character in the same matrix.
Conclusion
In this article,we have seen about different R data types that are supported by the R programming language. In the R programming language, data types play a crucial role as this is basic building blocks.
Recommended Articles
This is a guide to R Data Types. Here we discuss the introduction, different types in R programming language and types of vector modes. You can also go through our other suggested articles to learn more –
Are you preparing for the entrance exam ?
Join our Data Analysis test series to get more practice in your preparation
View More