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
The investor has constant wealth 1 and is o?ered to invest in shares of a project that either gains 3=2 or loses 1 with equal probabilities. Therefore, if the investor obtains sha

Canonical correlation analysis (CC) allows the investigation of the relationship between two ,sets of variables. For example, a sociologist may want to investigate the Relationship

a) List down several measures of central tendency and define the difference among them? b) What do you mean by confidence interval, and why it is useful? What is a confidence lev


how can we graph a trend line by semiaverages and least square method?

Statistician is searching the \home ground" effect and is studying 20 football games, of which 14 were won by the home team and 6 by the visitors. Therefore the game is a Bernoulli

Test the following claim. Identify the null hypothesis, alternative hypothesis, test statistic, critical value(s), conclusion about the null hypothesis, and final conclusion that

what do we mean by critical region

Is the random vector (Trunk Space, Length, Turning diameter) of US car normally distributed? Why? If yes, find the unbiased estimators for the mean and variance matrix of (Trunk Sp

The box plot displays the diversity of data for the age; the data ranges from 19 being the minimum value and 60 being the maximum value. The box plot is positively skewed at 0.57 a