Question with R - Bioinformatics, Applied Statistics

Assignment Help:
Hi There,

I have a question regarding R, and I am wondering if anyone can help me.

Here is a code that I would like to understand:

squareFunc <- function(f) {
g <- function(x) {
f(x)^2
}

return(g)
}

sin.2 <- squareFunc(sin)

sin.2(1)


In the above code, function sin is nested in suquareFunc, which also has a function g inside.

I am having hard time understanding this code.

For example, if I was asked to write this code, mine would look like:

squareFunc <- function(f) {
g <- f^2
return(g)
}

sin.2 <- squareFunc(sin)

sin.2(1)

and this does not work.


I feel that argument ''f'' in in squareFunc(f) should be passed on to the function ''g'', but what g has is (x).

Obviously the first code works if I type it in R, but I would like to understand how it works.

I may not be asking the right question, but if you can see where I am confused at and can help me to understand it, that would be great.

Thank you very much in advance.

Mayumi

Related Discussions:- Question with R - Bioinformatics

Perform clustering of the unlabeled data set, Perform clustering of the unl...

Perform clustering of the unlabeled data set. You could use provided initial centroids set or generate your own. Also there could be considered next stopping criteria : - maxim

#Probablility, #In planning the teaching assignments for next semester, Mr....

#In planning the teaching assignments for next semester, Mr. Hinton must have a teacher in each of the 7 grades during each of the 6 periods of the day. If he has 10 teachers to ch

Implement a simple k-means method, There exists an unclassified data set wi...

There exists an unclassified data set with hidden data structures in it. The task in this assignment is to perform comprehensive Cluster Analysis in order to reveal the structures

Determine the closed loop speed transfer function, In the case of permanent...

In the case of permanent magnet DC motor whose stator consists of a permanent magnet we can take the field current to be constant (i.e. a constant magnetic field) and it can be sho

Regression model, A real estate agency collected the data shown below, wher...

A real estate agency collected the data shown below, where           y  = sales price of a house (in thousands of dollars)           x 1 = home size (in hundreds of square f

Probability of remaining paint free, In a three-cornered paint ball duel, A...

In a three-cornered paint ball duel, A, B, and C successively take shots at each other until only one of them remains paint free. The three paint ballers have different probabiliti

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd