## How to Use LETTERS in R (With Examples)

In R, LETTERS is a built-in constant that represents a character vector containing the 26 uppercase letters of the English alphabet. Syntax LETTERS Visual Representation Example 1: Basic usage print(LETTERS) Output [1] “A” “B” “C” “D” “E” “F” “G” “H” “I” “J” “K” “L” “M” “N” “O” “P” “Q” “R” “S” [20] “T” “U” “V” … Read more

## How to Convert Character Vector to Numeric in R

To convert a character vector to numeric in R, use the as.numeric() function. It creates or coerces objects of type “numeric”. Syntax num_val <- as.numeric(x) Example 1: Converting character vector to numeric char <- as.character(sample(c(19, 11, 46, 21), 10, replace = TRUE)) char typeof(char) num <- as.numeric(char) num typeof(num) Output [1] “21” “19” “46” “46” … Read more

## R as.Date() Function: Working with Dates

The as.Date() function in R converts various types of date and time objects or character strings into Date objects. Syntax as.Date(x, format, tryFormats = c(“%Y-%m-%d”, “%Y/%m/%d”), optional = FALSE, tz = “UTC”) Parameters Name Description x It is an object to be converted. format It is a character string. If the format argument is not … Read more

## Logical OR ( | ) Operator in R

You can represent the OR operator in R as “|” for element-wise comparison and “||” for a single comparison between two elements. It returns TRUE if one of the conditions is TRUE. If both conditions are FALSE, it will return FALSE. The OR operator is similar to the AND operator, with one difference: Only one of … Read more

## R rep() Function: Replicating Elements of a Vector

R rep() function replicates elements of vectors and lists for a specific number of times. When working on a project, you may need to create dummy data to expand your dataset in various contexts, such as data preparation, simulation, and test data generation. In that case, the rep() function is beneficial. Another use case is … Read more

## How to Create an Empty Vector in R

Here are six methods to create an empty Vector in R: Using vector() function Use c() function Using numeric() function Using character() function Using rep() function Assigning NULL to an existing vector Method 1: Using vector() The easiest way to create an empty vector is to use the plain vector() function without arguments. rv <- … Read more

## How to Create an Empty List in R

You may be wondering, Why should I create an empty list? Well, sometimes, you need to start with nothing—an empty canvas—and then fill it with amazing colors. The same logic applies to an empty list. Start with an empty list and fill the list with proper elements. Here are three ways to create an empty … Read more

## How to Check Data type in R

Here are five ways to check data type in R: Using class(): For checking a single variable. Using str(): For checking the data type of every variable in a data frame. Using typeof(): For checking more basic data type of the object. Using is.* Functions: For checking specific data types. Using mode() (not recommended): For checking … Read more

## Splitting Strings Made Easy: A Beginner’s Guide to strsplit() in R

Picture this: You have a long string of text and want to break it into smaller chunks separated by commas and separate each element. How do you do it? Well, the answer is the strsplit() function in R. The strsplit() function splits elements of a character vector into substrings based on the input delimiter. Let’s … Read more

## Pi in R: Built-in Constants

Pi is a built-in R constant whose value is 3.141593. Pi is the ratio of the circumference of a circle to its diameter. Syntax pi Visual representation Example 1: Basic usage print(pi) Output [1] 3.141593 Example 2: Exponential value of pi To calculate the exponential value of pi, use the exp() function. exp(pi) Output [1] … Read more