How to Use the str_glue() Function in R

How to Use the str_glue() Function in R

The str_glue() function in R’s stringr package is “used to concatenate strings together, often using variables within the string.” Syntax str_glue(…, .sep, .envir = parent.frame(), .x, .na = “NA”) Parameters …: These are the strings to be concatenated. Strings can be a mix of constants and expressions enclosed in {}. The expressions within {} will … Read more

How to Use the str_detect() Function in R

How to Use the str_detect() Function in R

The str_detect() function from the stringr in R is “used to detect the presence or absence of a specific pattern in a string.” Syntax str_detect(string, pattern, negate = FALSE) Parameters string: It is a character vector. pattern: It is the pattern to look for. negate: If TRUE, return non-matching elements. Example 1: Using str_detect() function … Read more

How to Calculate Mean / Average in R

How to Calculate Average in R

To calculate a mean or average in R, you can “use the mean() function.” For example, mean(c(1, 2, 3, 4)) function returns 2.5. Syntax mean(x, trim, na.rm) Parameters x: The x is a Numeric Vector. trim: It drops some observations from both ends of the sorted vector. na.rm: It is a boolean value to ignore the NA … Read more

What is the do.call() Function in R

What is the do.call() Function in R

The do.call() function in R is “used to construct and execute a function call from a name or a function, as well as a list of arguments to be passed to it.” Syntax do.call(what, args) Parameters what: It represents either the function or a non-empty character and names the function to be called. args: It … Read more

R If then Statement (With Examples)

How to Use If then in R

Use the “if() {}” function to create an if-then statement in R. The if() function has two main elements, a logical test in the parentheses and conditional code in curly braces. The code in the curly braces is conditional because it is only evaluated if the logical test contained in the parentheses is TRUE. Syntax … Read more

How to Install RStudio on Mac

How to Install RStudio in Mac

To install R on Mac, follow the below steps. Open the web browser and go to www.r-project.org. Click the “Download R” link in the middle of the page under “Getting Started.” Select the nearest region’s CRAN location (a mirror site) and click the corresponding link. Click on the “Download R for (Mac) OS X” link at … Read more

How to Create a List in R

How to Create a List in R

To create a list in R, you can use the “list()” function. The “list()” function accepts single or multiple arguments and returns the list. lt <- list(“SBF”, “Alameda”) print(lt) Output [[1]] [1] “SBF” [[2]] [1] “Alameda” You can see that we created a list with two elements. To print the data in the console, use … Read more

How to Use the c() Function in R

c Function in R - How to Create Vector using c() Function

The c() function in R is “used to combine or concatenate its argument”. The c() stands for “combine”. It returns the output by giving parameters inside the function. Syntax c(…, recursive = FALSE, use.names = TRUE) Parameters …: They are the objects to be concatenated. recursive: It is logical. If recursive = TRUE, the function recursively descends … Read more