To start programming in any language, we may need to create variables to store some information. Now, this information can be numeric, or character or a Boolean value. Based on the data type of this variable, the OS allocates memory to decide what can be stored in the reserved memory.
R works with numerous data types. The most basic ones are as follows:
-
Decimals values are called numeric.(e.g. 2.2)
-
Natural numbers are called integers. Integers are also numeric.(e.g. 5)
-
Boolean values are called logical.(e.g. TRUE /FALSE)
-
Text (or string) values are called character.(e.g. “Test R”)
Problem:
Assign values to some variables of Different Data Types and then play with those variables.
Solution:
1. To assign a value to a variable in R, we need to use the assignment operator “<-“.
|
Assign values to Variables
|
2. To print the values of these variables, we can just type the variable name. Also, we can use the “Print()” command to display the variable value.
|
Print the variable values
|
Use of Print() Funtion
|
3. To determine the Data Type of a variable, we can use the Class() Function like below
|
Check the Data Type of the Variables
|
4. To list the variables that are defined in my workspace, we can use ls() function as below:
5. To delete a variable, we need to use rm() function as below:
The above are the most basic data types and some basic operations on the variables. To understand R and write some code in R, we need to learn about some complex Data types. Please find the links below:
Start Learning and Happy Coding!