Why do we use apply() function in R?

This is used to apply the same function to each of the elements in an Array. For example, finding the mean of the rows in every row. In R, the apply() function is used to apply a specified function to the rows or columns of a matrix or data frame. The primary purpose of using … Read more

Differentiate b/w “%%” and “%/%”.

The “%%” provides a reminder of the division of the first vector with the second, and the “%/%” gives the quotient of the division of the first vector with the second. In R, “%%” and “%/%” are both operators related to division, but they serve different purposes: “%%” (modulo operator): The “%%” operator calculates the … Read more

Give the command to create a histogram and to remove a vector from the R workspace?

hist() and rm() function are used as a command to create a histogram and remove a vector from the R workspace. To create a histogram in R, you can use the hist() function. Here’s a simple example: # Create a histogram for a vector ‘data’ data <- c(1, 2, 2, 3, 3, 3, 4, 4, … Read more

Why do we use the command – install.packages(file.choose(), repos=NULL)?

This command is used to install an R package from the local directory by browsing and selecting the file. The command install.packages(file.choose(), repos=NULL) in R is used to install a package from a local file. Let’s break down the components of this command: file.choose(): This function opens a file dialog box, allowing the user to … Read more

What is the difference b/w sample() and subset() in R?

In R, sample() and subset() are two different functions with distinct purposes: sample(): sample() is used for generating random samples from a specified set of elements. It can be used to randomly permute a vector or to randomly select elements from a vector. The basic syntax is sample(x, size, replace = FALSE), where x is … Read more