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
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

give a elementary example for characterstics of index number

You were recently hired by E&T Boats, Inc. to assist the company with its financial planning and to evaluate the company's performance.  E&T Boats, Inc. builds and sells boats to o

Asymmetric proximity matrices Immediacy matrices in which the off-diagonal elements which are, in the i th row and j th column and the j th row and i th column, are not essent

Apl.send me nots on hypothesis testing sk question #Minimum 100 words accepted#

The data in the data frame compensation are from Myers (1990), Classical andModern Regression with Applications (Second Edition)," Duxbury. The response y here is executive compens

The total number of overtime hours (in 1000s) worked in a large steel mill was recorded for 16 quarters, as shown below. Year Quarter Overtime hour

In an examination 600 candidates appeared, boys outnumbered girls by 16% of all candidates. number of passed candidates exceeded the number of failed candidates by 310. Boys failin

Make a decision about the given claim. Do not use any formal procedures and exact calculation. Use only the rare event rule. Claim: A coin favors head when tossed, and there

Calculation for Discrete Series or Ungrouped Data The formula for computing mean is = where,          f  = fr