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
for this proportion, use the +-2 rule of thumb to determine the 95 percent confidence interval. when asked if they are satisfied with their financial situation, .29 said "very sat

What is a null hypothesis? ..

Dr. Jim Mirabella UNIT EIGHT: DATA ANALYSIS PROJECT All Excel output should be copied into a single Word document where you must enter all of your responses to the questions below.

Confirmatory factor analysis (CFA) seeks to determine whether the number of factors and the loadings of measured (indicator) variables on them conform to what is expected on the ba

Measurement of trend , least square method

b. A paper mill produces two grades of paper viz., X and Y. Because of raw material restrictions, it cannot produce more than 400 tons of grade X paper and 300 tons of grade Y

The interest rate on the three year loan is 0.087. Whereas the interest rate on the two year loan is 0.085 as given in A. Suppose that the liquidity premium at t=1 is 0.002 and tha

Disadvantages The value of mode cannot always be determined. In some cases we may have a bimodal series. It is not capable of algebraic manipulations. For example, from t

for this proportion, use the +-2 rule of thumb to determine the 95 percent confidence interval. when asked if they are satisfied with their financial situation, .29 said "very sat

entropy test to measure interaction between enviornmental factors and genes