Senny

Her proposal was sincere. The beach house would make a perfect place for us. Everything she said to me was so right. Her face was unwavering. The evening breeze moved her hair, but not her resolve. I…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Applying Functions In R

The article starts with creating and calling built-in, user-defined, in-line, and anonymous functions in the R programming language. Then we will learn how to apply different built-in R functions such as mean, median, sd, and var on datasets of a different kind such as matrix, data frame, list, vector, etc. In this article, we will learn the following functions.

For example, we have a vector v and we want to take the mean of the vector elements.

For example, I have a matrix A and I want to calculate its rows sum and its columns sum.

In R we will use apply(data, margin, fun).

apply(matrix, 1, function)

apply(matrix, 2, function)

Now we want to calculate the sum, variance, standard deviation, and means of the matrix row-wise and column-wise.

For example, we have data in celsius and we want to convert this data into Fahrenheit. First, we create a function f(c) that takes the temperature in celsius and returns in the Fahrenheit scale.

Now I have temperature data (in celsius) in a matrix and want to convert it into a Fahrenheit scale.

anonymous functions have no name and they can not be called by name, First, we make a named function f() that convert temperature from celsius to Fahrenheit. then we create an anonymous function and call the function.

First, we pass the named function g() to apply, which takes the square root of the given argument.

Now, we pass the anonymous function to apply, which takes the square root of the given argument.

It iterates over list elements and applies a function to each element. It is much faster than apply() function.

It iterates over list or vector elements and applies a function to each element. It is much faster than apply() function.

sapply() take two arguments first is list or vector and second is function.

vapply() is slightly different from sapply() or lapply() with minor speed improvements. Type checking is compulsory on output.

Why Type Check?

If you want an output of a specific type then identify bugs early. It checks the type of output before running.

It take 2-arguments

return the n number from a uniform distribution between 0 and 1

repeat expr value n times

In this article, we learn how to apply different built-in functions such as standard deviation, variance, and mean on the data structure of different kinds such as data frame, matrix, list, and vectors.

Add a comment

Related posts:

Searching For an Extra Gear

Searching For an Extra Gear. Can high tech revive productivity? A lot is riding on the outcome. New SAGE Business Researcher at http://tinyurl.com/y9fxwm2v explores the….

Monolith Chapter II.

The rain had stopped and the sky was unsurprisingly overcast. Wishing to honor the traditions of the city, I boarded the black TXII, the newest version of the iconic London Taxis International…

What To Look For In A Content Publishing Platform

Establishing a successful publishing business is not an easy task. There are a number of things to take care of. The very first thing a publishing business requires is the right content publishing…