Fundamentals & Core programming principles of R Language in Data Science:

Here we will be learning very sophisticated Things in R, we will go through step by step the deep Programming Contents like Vectors, Matrices, data Frames and so on … To get Accustomed to this Deeper Programming, we will start with the very Basic Fundamentals.

1.Types of Variables:

Here Let’s Look at the five different Data types which are also called the atomic data Types in R.

Prerequisites to learn before we start:

  • Hash Tag in R language is to provide Comments, code Readability and Those Lines of code will not be executed.
  • <- This is an Assignment operator
  • To clear the Previous console Code, Go to Console Pane and enter Control + L Key combination to clear the previous console history
  • To clear the Variables in Environment Pane, there is a Brush Button on the Environment pane, Click on Brush button to clear the previous Environment History

Let’s start with Integer Data type

  1. Integer:

Code: 

  • # Integer
  • x <- 2L

Here Variable X = 2 is assigned and L represents the Integer Data type. Run the Line 3, the output is copied in Console Pane and Output shown in the environment pane. Now let’s Check what is the Data Type Variable X is holding

Code:

  • # Integer
  • x <- 2L
  • typeof(x)

In the console pane we can see that the data type of X is Integer.

We Have successfully Created our first integer, Now Let’s Look at another Data type.

2.Numeric / Double: As we are aware that Double means which Hold decimal Values

Code:

  • # Double
  • y <- 2.5
  • typeof(y)

Here Value  of Y is assigned is 2.5, when You execute this line of code,  we can see the Y value as 2.5 in Environment pane and  also we checked in console Pane  the  data Type Y is holding Double .

Note: as we understand Now, R Language by default stores the data of type Double, All the operations, calculations in R are conducted in Doubles because R Language anticipates all the arithmetic operations should be done with Double data type ,so it is Mandatory to mention  the L for integer Variable assignments .

3. Complex Data Type : R supports complex data types which are set of all the complex numbers. The complex data type is to store numbers with an imaginary component

Code:

  • # Complex
  • z <- 3 + 2i
  • typeof(z)

Here z variable is assigned to addition of Integer and Imaginary Number.

4.Character data type:

R supports character data types where you have all the alphabets and special characters. It stores character values or strings. Strings in R can contain alphabets, numbers, and symbols. The easiest way to denote that a value is of character type in R is to wrap the value inside single or double inverted commas.

Code:

  • # Character
  • a <- “Practicing R Language”

Run the above two lines Of Code, we can see the assigned string Value in Console Pane.

 Now Let’s see the Data type of variable A in Console Pane .

5.Logical data Type: Logic Data Types are either True or False.

Code:

# Logical

q1 <- T

Here the Variable q1 is assigned True, Run the Below line of code and we can see the assignment of q1 in Environment pane.

The data Type of q1 Variable is Logical.

Hope You Understand Datatypes in R, Now Try experimenting each data types with different variables.

Let’s explore Logical variables and operators in next Post.  Keep Coding … 😊

0 0 votes
Article Rating
1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments