1. Home
  2. Articles
  3. Courses
    1. Articles
  4. Community
  5. Definitions
  6. Files
    1. Terms Of Condition
  • Login
  • Register
  • Search
R Programming
  • Everywhere
  • R Programming
  • Articles
  • Pages
  • Forum
  • Definitions
  • Course Articles
  • Filebase Entry
  • More Options
  1. Scientific Tools
  2. Scientific Tools Articles
  3. R Programming

What are the Data Types in R ?

  • SciTools
  • 0 Comments

Data Types or Data Structures in R Programming: Scalars, Vectors (numerical, character, logical), Matrices , Data frames and Lists

Contents [hideshow]
  1. Scalars
  2. Vectors
  3. Matrices
  4. Data frames
  5. Lists
  6. Examples
    1. Example 1
    2. Example 2
    3. Example 3

This article is part of R-Basics learning materials:

Data types play a crucial role in programming languages as they define the kind of data that can be stored and manipulated. In R programming, various data types are available, each serving a specific purpose. This article provides an overview of the fundamental data types in R and demonstrates how to determine the type of a variable using the class function.

R Data Types:

Scalars

Scalars represent single values in R. They include numeric scalars (e.g., 4.5), integer scalars (e.g., 4), logical scalars (TRUE or FALSE), and character scalars (text enclosed in quotes, e.g., "R is fantastic").

Vectors

Vectors are one-dimensional arrays that can contain multiple values of the same data type. R supports numerical vectors, character vectors, and logical vectors. Numerical vectors hold numeric values, character vectors store text data, and logical vectors contain logical (Boolean) values.

Matrices

Matrices are two-dimensional data structures with rows and columns. They can be thought of as a collection of vectors of the same length. Matrices are often used for mathematical computations and data analysis.

Data frames

Data frames are similar to matrices but can hold different types of data. They are tabular structures with rows and columns, where each column can have a different data type. Data frames are commonly used to represent datasets, with each column representing a variable and each row representing an observation.

Lists

Lists are versatile data structures that can hold elements of different types. They can contain vectors, matrices, data frames, or even other lists. Lists provide flexibility and are useful when dealing with complex data structures.

Examples

Example 1

R
# Numeric
age <- 28
class(age)

Output:

R
[1] "numeric"

Example 2

R
# Character
message <- "R is amazing"
class(message)

Output:

R
[1] "character"

Example 3

R
# Logical
is_r_fun <- TRUE
class(is_r_fun)

Output:

R
[1] "logical"

Understanding data types is essential for effective programming in R. Scalar values, vectors, matrices, data frames, and lists offer different ways to structure and manipulate data in R. By utilizing the class function, you can easily determine the data type of a variable, ensuring proper data handling and analysis in your R programs.

  • Previous Article How to install a R package?
  • Next Article How to check if an R package is installed using RStudio

Categories

  1. R Programming 14
  2. Linux 0
  3. Reset Filter
  1. Privacy Policy
  2. Legal Notice
Copyright© ScientificTools.org 2025. All rights reserved.
All the content posted on this website are licenses by MySecure Space GmbH under Creative Commons CC BY-NC-ND 4.0
Creative Commons CC BY-NC-ND 4.0
Developed & Hosted by: MySecure.Space | Powered by: WoltLab Suite™