## R If else Statement (With Examples)

The if else statement in R “evaluates a condition and executes different statements based on whether the condition is TRUE or FALSE”. Syntax if (condition) { expression A } else { expression B } Here, the “condition” is an expression that evaluates to TRUE or FALSE. If the condition is TRUE, the code within the first … Read more

## R Operators: Arithmetic, Relational, Logical, Assignment

An operator in R is a symbol that tells the compiler to perform a mathematical or logical operation. Types of operators Arithmetic Operators Relational Operators Logical Operators Assignment Operators Miscellaneous Operators Arithmetic Operators in R Add(+) operator in R To add two vectors, you can use the “+ operator”. a <- c(1, 2, 3) b … Read more

## R Variables and Constants: The Definitive Guide

Variables in R can store an atomic vector, a group of atomic vectors, or different R Objects. To consider a valid variable name in R, the name consists of letters, numbers, and a dot or underlined characters. In the current version of R, there is support for underscore (_) as a valid identifier. Still, it … Read more

## R Data Types: Vector, List, Matrix, Array, and Data frame

R data types are the essential features that accept and store various data types. Some of the most common data types in R are: numeric: Decimal numbers like 10.5, 55, 787. integer: Whole numbers like 1L, 55L, and 100L (the letter “L” declares this as an integer). character: Strings of text like “hello”, “R”, and … Read more

## How to Find the Second and Third Lowest Values in Data Frame Column in R

To find the second and third lowest values in R Data Frame Column, you can use the “sort()” method. df <- data.frame( name = c(“A”, “B”, “C”, “D”, “E”, “F”, “G”), value = c(51, 12, 41, 21, 20, 81, 11) ) # Second and third lowest values sorted_values_asc <- sort(df\$value, decreasing = FALSE) second_lowest_value <- … Read more

## Pi in R Tutorial with Example

Pi is a built-in R constant whose value is 3.141593. The pi constant is the ratio of the circumference of a circle to its diameter. When you define a pi, please note that p of pi is in lowercase. Syntax pi Example print(pi) Output [1] 3.141593 The value of the pi constant in R is … Read more

## R Array: How to Create, Access, and Modify Array Elements

An array in R is a list or vector with two or more dimensions. An array is like a stacked matrix, and a matrix is a two-dimensional array. R arrays are objects which can store data in more than two dimensions. How to Create an Array in R To create an array in R, you can … Read more