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
Complete the multiple regression model using Y and your combined X variables.  State the equation.  Next, make sure that you evaluate overall model performance with the Anova table

Standard Deviation  The concept of standard deviation was first introduced by Karl Pearson in 1893. The standard deviation is the most important and the popular measure of disp

What is a null hypothesis? ..

give me question on mean is the aimplest average to understand and easy to compute


PCA is a linear transformation that transforms the data to a new coordinate system such that the greatest variance by any projection of the data comes to lie on the first coordinat

Q. The following system of equations illustrates the algebraic form of a partial (individual) market equilibrium model, which is a model of price (P) and quantity (Q) determination

give me question on mean is the aimplest average to understand and easy to compute

mark number of student 0-10 4 10-20 8 20-30 11 30-40 15 40-50 12 50-60 6 calculate frequency distribution

What is an example of a real life situation when I would use each of these test