R-logo
Data types are an integral part of any programming language. They are one of the pioneer building blocks and the development of any programming language usually revolves around them. Consider data types as the oxygen of any programming language. Important for their existence. The same is the case with R Programming.
If we assign any decimal value to a variable it becomes a variable of a numeric data type
> x <- 45.6
> class(x)
[1] "numeric"
To create an integer variable in R, we need to call the (as.Integer) function while assigning value to a variable.
> e <- as.integer(3)
> class(e)
[1] "integer"
Another way of creating an integer variable is by using the L keyword as follows:
> x <- 5L
> class(x)
[1] "integer"
R also supports a complex data type under its environment.
A complex number is a combination that can be expressed in terms of a + bi where bi is the imaginary part and a, b are the real numbers.
> x <- 2 + 3i
> class(x)
[1] "complex"
This data type is used to represent strings.
> x <- "Hello World"
> class(x)
[1] "character"
We can also use the as.character() function to convert objects into character values.
> x < as.charater(10.11)
> print(x)
[1] "10.11"
> class(x)
[1] "character"
A logical data type stores either of the two values: TRUE -/FALSE. A logical value is often generated when two values are compared.
> x <- TRUE
> y <- FALSE
> class(x)
[1] "logical"
> print(x & y) // Logical AND operation of TRUE and FALSE is FALSE
[1] FALSE
We have covered the basic syntax to writing a program in R, along with learning what a variable is and how to define a variable we also discussed how to store data with different data types in r programming
This brings the end of this Blog. We really appreciate your time.
Hope you liked it.
Do visit our page www.zigya.com/blog for more informative blogs on Data Science
Keep Reading! Cheers!
Zigya Academy
BEING RELEVANT
Controlling immunological responses requires the cytokine interleukin-2 (IL-2), commonly referred to as IL-2 Human. It…
What is Mortgage Insurance? Mortgage insurance is a type of insurance policy designed to protect…
Through the standard form offers different advantages in mathematical calculations and scientific notation. Firstly, it…
Introduction Stress is a feeling caused by an external trigger that makes us frustrated, such…
Sociology is a broad discipline that examines societal issues. It looks at the meaningful patterns…
Some info about Inch Inches are a unique measure that persuades us that even the…