Question with R - Bioinformatics, Applied Statistics

Assignment Help:
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

Related Discussions:- Question with R - Bioinformatics

E-mail messages should be answered quickly, Do people of different age grou...

Do people of different age groups differ in their response to e-mail messages? A survey by the Cent of the Digital Future of the University of Southern California reported that 70.

Production took place, Scenario: To fundraise for middle school camp the ye...

Scenario: To fundraise for middle school camp the year 3 and 4 syndicate designed and produced chocolate treats to sell to the year 1 and 2, and year 5 and 6 students at morning te

Cluster analysis, Cluster Analysis could be also represented more formally ...

Cluster Analysis could be also represented more formally as optimization procedure, which tries to minimize the Residual Sum of Squares objective function: where μ(ωk) - is a centr

Types of business forecasting , Types  of business forecasting  are genera...

Types  of business forecasting  are generally as follows: 1.      Sales  and Demand  forecasts 2.      Porduction  forecasts. 3.       Cost  Forecasts 4.       Financi

Types of cost-reimbursable contracts, Types of cost-reimbursable contracts ...

Types of cost-reimbursable contracts are:   Cost Plus Fixed Fee contract (CPPF): Compensation is based on a fixed sum independent of the final project cost. The customer a

Statistical generalisations, From the information given, what seems to be t...

From the information given, what seems to be the main flaw in each of the following statistical generalisations? (i) Banking industry employees are facing a crisis, if their

Regression analysis, Meaning and Definitions of Regression The dictiona...

Meaning and Definitions of Regression The dictionary meaning of regression is just opposite the meaning of progression. Progression means to move forward while regression means

Measures of dispersion, Other Measures of Dispersion In this section, ...

Other Measures of Dispersion In this section, we look at relatively less used measures of dispersion like fractiles, deciles, percentiles, quartiles, interquartile range and f

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd