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
What is an interaction? Describe an example and identify the variables within your population (work, social, academic, etc.) for which you might expect interactions?

Assume that a simple random sample has been selected from a normally distribute population and test the given claim. Identify the null and alternative hypotheses, test statistic,

The box plot displays the diversity of data for the income; the data ranges from 20 being the minimum value and 1110 being the maximum value. The box plot is positively skewed at 4

Universe or Population The word universe as used in statistics denotes the aggregate from which a sample is to be taken. According to Simpson and Kafka, a universe or populatio


what is the aim of statistics?

 Each question, by default, should be solved INDIVIDUALLY, unless marked as \collaborative". Questions marked as \collaborative" implies that for those questions you are encourage

Framing of Questionnaire: Questionnaire is a schedule of questions which is sent to the respondents for filling in by them in their own handwriting together the information rel

Using Chi Square Test when more than two Rows are Present   To understand this, let us consider the contingency table shown below. It gives us the information about the stage

Definition of Correlation According  to prof, king correlation means that between two series or group  of data  there  exists  some casual connection  prof, king  has also  exp