Question with R - Bioinformatics, Applied Statistics

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
Posted Date: 1/20/2013 8:46:28 PM | Location : Canada







Related Discussions:- Question with R - Bioinformatics, Assignment Help, Ask Question on Question with R - Bioinformatics, Get Answer, Expert's Help, Question with R - Bioinformatics Discussions

Write discussion on Question with R - Bioinformatics
Your posts are moderated
Related Questions
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

For a distribution of scores with = 82 and standard deviation = 2.5, find the following: (Don't forget to sketch the normal curve to help you visualize what you are trying to fi

The PCA is amongst the oldest of the multivariate statistical methods of data reduction. It is a technique for simplifying a dataset, by reducing multidimensional datasets to lower

The following data on calcium content of wheat are consistent with summary quantities that appeared in the article “Mineral Contents of Cereal Grains as Affected by Storage and Ins

Select and generate your assignment portfolio. The S&P/ASX 200 index is comprised of several sub-indices, including the following: 0) XPJ: The S&P/ASX 200 A-REIT Index 1) XDJ

The Null Hypothesis - H0:  The random errors will be normally distributed The Alternative Hypothesis - H1:  The random errors are not normally distributed Reject H0: when P-v

Define sampling unit and population for selecting a random sample in every case. a) 100 voters from a constituency b) 20 stocks of National Stock Exchange c) 50 account ho

Examine properties of good average with reference to AM, GM, HM, MEAN MEDIAN MODE

Analysis of Variance for the data: Draw a random sample of size 25 from the following data : (a) With Replacement and   (b) Without Replacement and obtain Mean and Varia

Examine the given statement, then express the null hypothesis H0 and the alternative hypothesis H1 in symbolic form. The mean weight of women who won a beauty pageant is equal t