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

Properties of standard deviation, PROPERTIES   1. The value of stand...

PROPERTIES   1. The value of standard deviation remains the same if, in a series each of the observation is increased or decreased by a constant quantity. In statistical lan

Assumptions in anova, Assumptions in ANOVA The various populations f...

Assumptions in ANOVA The various populations from which the samples are drawn should be normal and have the same variance. The requirement of normality can be discarded if t

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

Practice-Based Evidence, how to analyzePractice-Based Evidence Back to the ...

how to analyzePractice-Based Evidence Back to the Future

Liner programming , Solve the following Linear Programming Problem using S...

Solve the following Linear Programming Problem using Simple method. Maximize Z= 3x1 + 2X2 Subject to the constraints: X1+ X2 = 4 X1 - X2 = 2 X1, X2 = 0

Two-tailed and one-tailed tests, If the test is two-tailed, H1:  μ ≠  μ 0  ...

If the test is two-tailed, H1:  μ ≠  μ 0  then the test is called two-tailed test and in such a case the critical region lies in both the right and left tails of the sampling distr

Probability of remaining paint free, In a three-cornered paint ball duel, A...

In a three-cornered paint ball duel, A, B, and C successively take shots at each other until only one of them remains paint free. The three paint ballers have different probabiliti

Critique 2, prepare a critical analysis of a quantitative study focusing on...

prepare a critical analysis of a quantitative study focusing on protection of human participants data collection data management and analysis problem statement and interpretation o

Box plots, This box plot displays the diversity wfood; the data ranges from...

This box plot displays the diversity wfood; the data ranges from 0.05710 being the minimum value and 0.78900 being the maximum value. The box plot is slightly positively skewed at

Stratified sampling, Stratified Sampling Stratified Sampling is ...

Stratified Sampling Stratified Sampling is generally used when the population is heterogeneous. In this case, the population is first subdivided into several parts (or s

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