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
Cluster Sampling Here the population is divided into clusters or groups and then Random Sampling is done for each cluster. Cluster Sampling differs from Stratified Sampl

We want to investigate the income data.  In the Excel file Midterm  Data.xls there is a tab labeled "Income Data 2006".  The data in the tab is the income reported by 400 people in

Primary and Secondary Data: Primary Data: These data are those are collected for the first time. Thus primary data are original in character and gathered   by actual observat

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


Consider three stocks A, B and C costing $100 each. The annual returns on the three stocks have mean $5 and variance $10. a. Suppose that the returns on the three stocks are i.i

difference between large sample test and small sample test

Question: (a) (i) Define the term multicollinearity. (ii) Explain why it is important to guard against multicollinearity. (b) (i) Sometimes we encounter missing values

a) List down several measures of central tendency and define the difference among them? b) What do you mean by confidence interval, and why it is useful? What is a confidence lev

Is the random vector (Trunk Space, Length, Turning diameter) of US car normally distributed? Why? If yes, find the unbiased estimators for the mean and variance matrix of (Trunk Sp