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
You are going to purchase a part from a specialty vendor.  Your company needs a C p of at least 1.67 on a critical dimension of the part.  The dimensional specification for this p

The file Midterm Data.xls has a tab labeled "Income Data 2009". This data is collected income data from a sample of 400 people in 2009. Use a hypothesis test to see whether the av

Muti linear regression model problem An investigator is studying the relationship between weight (in pounds) and height (in inches) using data from a sample of 126 high school

Risk of Portfolios So far, we have seen the application of standard deviation in the context of risk in single investment. But usually most investors hold portfolios of securi

prove standard deviation of natural natural numbers

In a three-cornered paint ball duel, A, B, and C successively take shots at each other until only one of them remains paint free. Once hit, a player is out of the game and gets no


Determine the Effects of Stopping Smoking On Weight Gain As part of a study to determine the effects of stopping smoking on weight gain, nine females were weighed on the day t

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

The proportion of American Express credit-card holders who pay their credit card bill in full each month is 23%; the other 77% make only a partial or no payment. (a) In a random