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
PROPERTIES   1. The value of standard deviation remains the same if, in a series each of the observation is increased or decreased by a constant quantity. In statistical lan

Two individuals, player 1 and player 2, are  competing in an auction to obtain a valuable object. Each player bids in a sealed envelope, without knowing the bid of the other player



How vital statistics are affects on our human life

In this problem, we use the CSDATA data set, which is available in 'CSDATA.txt'. We do ne an indicator variable, say HIGPA, to be 1 if the GPA is 3.0 or better and 0 other- wise. S

Formation of Continuous Frequency Distribution:    Continuous frequency distribution is most popular in practice. With reference to the formation of this type of frequency distr


Classification of Universe The universe may be classified either on the basis of number of units and on the basis   of existence of units as is clear from the following chart :

merits and demerits of methods to determin trends