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

Postneonatal mortality rate, Mid year population 440000 Late fatal death...

Mid year population 440000 Late fatal death          29 No. of live birth           5200 No. of infant death      423 No. of maternal death 89 No. of infant deaths i

Simple linear regression model, The data le for this assignment is brain-b...

The data le for this assignment is brain-body-wts.txt, which lists the averages brain weights (gm) and body weights (kg) for a number of animal species. Your task is to t an appr

Introduction to probability, Introduction to Probability A ...

Introduction to Probability A student is considering whether she should enroll in an MBA educational program offered by a well-known college. Among othe

Draw a network diagram for this problem, The project of building a backyard...

The project of building a backyard swimming pool consists of eight major activities and has to be completed within 19 weeks. The activities and related data are given in the follow

Confidence interval, for this proportion, use the +-2 rule of thumb to dete...

for this proportion, use the +-2 rule of thumb to determine the 95 percent confidence interval. when asked if they are satisfied with their financial situation, .29 said "very sat

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

discuss the advantages and disadvantages of measures of dispersions

Systematic random sampling, Systematic Random Sampling This method  is ...

Systematic Random Sampling This method  is generally used in such cases where a complete list of the population is available from which sample has to be selected. Under this

Correlation coefficient test, 1. If you are calculating a correlation coeff...

1. If you are calculating a correlation coefficient testing the relationship between height and weight, state the null and alternative hypotheses. 2. What kind of relationship d

Classical and modern regression, The data in the data frame asset are from ...

The data in the data frame asset are from Myers (1990), \Classical and Modern Regression with Applications (Second Edition)," Duxbury. The response y here is rm return on assets f

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

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