What is levels() Function in R

Levels in R - What are the Factor Levels

Levels in R are a way of defining the possible values of a factor variable. A factor variable is a categorical variable that can have one of a fixed set of values. For example, if you have a variable called gender, it can have two levels: male and female. You can use the levels() function … Read more

How to Export using write.csv() Function in R

How to Export DataFrame to CSV in R using write.csv()

The write.csv() is a built-in R function that writes data into a CSV file. It takes a data frame as data, a filepath as a file, and exports it to that file. Syntax write.csv(x, file, traitsAsDir = FALSE, csv2 = TRUE, row.names = FALSE, fileEncoding = “UTF-8” …) Parameters x: It is a data frame … Read more

What is the gl() Function in R

How to Generate Factor Levels in R using gl() Function

The gl() function in R generates factors by specifying the pattern of their levels. It takes two integers as input which indicates how many levels and how many times each level and returns factors. Syntax gl(n, k, length = n*k, labels = seq_len(n), ordered = FALSE) Parameters n: It is an integer giving the number … Read more

read.csv() Function: How to Read CSV File in R

How to Read CSV File in R using read.csv() Function

The read.csv() function in R reads comma-separated value (CSV) files into a data frame. It is a wrapper function for read.table() that specifies a comma as a separator and uses the first line of the file as column names. Syntax read.csv(“path to csv file”) Parameters The read.csv() function takes a csv file or path to … Read more

What is Structure() Function in R

R Structure() Function Example

The structure() is a built-in R function that returns an object with additional attributes. It helps create datasets within your code or display the internal structure of an R object. For example, you can create a data frame with specific names, classes, and dimensions. Syntax structure(.Data, …) Parameters .Data: an object which will have various … Read more

What is the ceiling() Function in R (5 Examples)

R Ceiling - How to Calculate Ceiling of Number in R

The ceiling() is a built-in R function that rounds up to the nearest integer. For example, ceiling(3.14) returns 4. Syntax  ceiling(x) Parameters The ceiling() function accepts one parameter whose value needs to be rounded off. If the x parameter is a positive or negative numeric value, the ceiling function returns the ceiling value. If it … Read more

How to Calculate Square Root in R

Square Root in R - How to Calculate Square Root of in R

Use the sqrt() function to calculate the square root of a numeric value or a vector in R. For example, sqrt(16) returns 4, and sqrt(c(1, 4, 9)) returns c(1, 2, 3). Syntax sqrt(n) Parameters The sqrt() function accepts only one parameter, which takes n as a number. Return value It returns the square root of the … Read more

What is map() Function in R

R Map: How to Install Purrr Package and Use map() in R

In R, the map() function is part of the purrr package, allows you to apply a function to each element of a vector or list, and returns the results as a new list. Syntax map(rv, func, …) Parameters The rv is an atomic vector or list. The func is a function, formula, or atomic vector. If it is a … Read more