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

Random sampling method, Random Sampling Method In this method the units...

Random Sampling Method In this method the units are selected in such a way that every item in the whole universe has an equal chance of being included. In the words of croxton

Quantitative and qualitative methods for forecasting sales, OmegaPlus Pty...

OmegaPlus Pty.Ltd. is a chain of Health Food stores operating in Australia: with 12 stores across Sydney, Melbourne and Brisbane. OmegaPlus has recently appointed a new CEO: San

Bienayme-chebyshev rule, This probability rule determined by the research o...

This probability rule determined by the research of the two mathematicians Bienayme' and Chebyshev, explains the variability of data about its mean when the distribution of the dat

Dispersion.., discuss the advantages and disadvantages of measures of dispe...

discuss the advantages and disadvantages of measures of dispersions

B) Distinguish between:, X 110 120 130 120 140 135 155 160 165 155 ...

X 110 120 130 120 140 135 155 160 165 155 Y 12 18 20 15 25 30 35 20 25 10

Binomial and continuous model, Exercise: (Binomial and Continuous Model.) C...

Exercise: (Binomial and Continuous Model.) Consider a binomial model of a risky asset with the parameters r = 0:06, u = 0:059, d =  0:0562, S0 = 100, T = 1, 4t = 1=12. Note that u

QHA, Your employer, Quick Hit Agency (QHA), is a debt collections agency. T...

Your employer, Quick Hit Agency (QHA), is a debt collections agency. The company specializes in collecting small accounts. QHA does not deal in large accounts and does not take on

Weibull distribution, slope parameter of 1.4 and scale parameter of 550.cal...

slope parameter of 1.4 and scale parameter of 550.calculate Reliability, MTTF, Variance, Design life for R of 95%

Chi square test, application of chi square test in civil engineering

application of chi square test in civil engineering

Quartiles, Related Positional Measures Besides median, there are other ...

Related Positional Measures Besides median, there are other measures which divide a series into equal parts. Important amongst these are quartiles, deciles and percentiles.

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