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
Zinc is a trace element and it is important in wound healing, building up the immune system and DNA synthesis. The data in Table 1 represents the zinc intake (in milligrams) for a

Coefficient of Determination The coefficient of determination is given by r 2 i.e., the square of the correlation coefficient. It explains to what extent the variation

CERTIFICATE OF AIRWORTHINESS FOR EXPORT When aircraft manufacturers go into series production of a new type of aircraft, then obviously they are hopeful of world wide sales. Sim

Where do I Access the gss04student_corrected dataset

Frequency distribution A frequency distribution is a series where a number of items with similar values are put in separate groups or bunches. In other words a frequency distri

The project of building a backyard swimming pool consists of eight major activities and has to be completed within 19 weeks. The activities and related data are given in the follow

Q. Find relative maxima and minima? When finding relative maxima and minima in the Chapters absolute extrema problem, don't forget to use the first or second derivative test to

Analysis of variance allows us to test whether the differences among more than two sample means are significant or not. This technique overcomes the drawback of the method used in

fixed capacitor and variable capacitor

There exists an unclassified data set with hidden data structures in it. The task in this assignment is to perform comprehensive Cluster Analysis in order to reveal the structures