Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

R Data Types


Sure! Data types in R represent the different kinds of values that variables can hold. Here's a simple explanation with examples:

1. Numeric:

Numeric data type represents numbers, including integers and decimals.

Example

# Integer
x <- 10

# Decimal (floating-point number)
y <- 3.14

2. Character:

Character data type represents text or strings.

Example

name <- "Alice"

3. Logical:

Logical data type represents boolean values - either TRUE or FALSE.

Example

is_valid <- TRUE
is_active <- FALSE

4. Integer:

Integer data type specifically represents whole numbers.

Example

count <- 5L

5. Complex:

Complex data type represents complex numbers with real and imaginary parts.

Example

z <- 3 + 4i

Checking Data Types:

You can check the data type of a variable using the class() function

Example

class(x) # This will return "numeric"
class(name) # This will return "character"
class(is_valid) # This will return "logical"
class(count) # This will return "integer"
class(z) # This will return "complex"

Conclusion:

Understanding data types is essential for working with data in R. Each data type has its own characteristics and operations that can be performed on it. By knowing the data type of your variables, you can write more effective and efficient code.


Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java