Recap of Essential R Programming Concepts

Recap of Essential R Programming Concepts

Are you excited to continue your journey in data science with R? In this section, we'll revisit some of the foundational R programming concepts you've already encountered, ensuring you're well-prepared for more advanced topics. Our focus will be on data structures, basic operations, control structures, and custom functions in R.

What You'll Learn

We'll cover the following key concepts in this lesson:

  1. Data Structures: Refresh your understanding of vectors, matrices, lists, and data frames.
  2. Basic Operations: Revisit arithmetic operations, calculating mean and sum, and type conversions.
  3. Control Structures: Recap how to use conditionals (if-else), loops (for, while), and custom functions in R.

Data Structures

Let's start by refreshing our knowledge of different data structures in R: vectors, matrices, lists, and data frames.

Vectors

Vectors are one-dimensional arrays that can hold numeric, character, or logical data types.

nums <- c(1, 2, 3, 4, 5)
print(nums)

In this example, nums is a numeric vector containing the numbers 1 through 5.

Matrices

Matrices are two-dimensional arrays that hold elements of the same data type.

matrix_example <- matrix(1:9, nrow = 3, byrow = TRUE)
print(matrix_example)

Here, matrix_example is a 3x3 matrix filled by rows with numbers from 1 to 9.

Lists

Lists in R can hold elements of different types, including other lists.

list_example <- list(nums, matrix_example, c("a", "b", "c"))
print(list_example)

In this example, list_example contains a vector, a matrix, and a character vector.

Data Frames

Data frames are two-dimensional tables where each column can hold different types of data.

df <- data.frame(ID = 1:3, Name = c("Alice", "Bob", "Charlie"), Score = c(9.5, 8.7, 9.8))
print(df)

Here, df is a data frame with three columns: ID, Name, and Score.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal