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

Probability, .1 Modern hotels and certain establishments make use of an ele...

.1 Modern hotels and certain establishments make use of an electronic door lock system. To open a door an electronic card is inserted into a slot. A green light indicates that the

Median, Median Median is a position average. It is the value of middle ...

Median Median is a position average. It is the value of middle item of a variable when the items are arranged according to their values either in ascending or descending order.

Sampling theory, difference between large sample test and small sample test...

difference between large sample test and small sample test

Sampling, Sampling A  Population  is a collection of all the data point...

Sampling A  Population  is a collection of all the data points being studied. For example, if we are studying the annual incomes of all the people in India, then the population

Evaluate minimum capability requirement, You are currently working wit...

You are currently working with a supplier who is producing a shaft whose diameter specification is 6.00 ± .003 inches.  Currently, the process is yielding shafts wit

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

Calculate the normal loss and abnormal loss, Chemical processors manufactur...

Chemical processors manufacture wondercool using two processes- mixing and distillation. The following details relate to the distillation process for a period. No opening work i

Standard erro, practical application of standard error

practical application of standard error

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