How to Use LETTERS in R (With Examples)

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

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

R as.Date() Function

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

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

How to Create an Empty Vector in R

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

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

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

Pi in R: Built-in Constants

Pi in R Tutorial

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