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

Different analyses of recurrent events data, Different analyses of recurren...

Different analyses of recurrent events data: The bladder cancer data listed in Wei, Lin, and Weissfeld (1989) is used in Example 54.8/49.8 of SAS to  illustrate different anal

Finding the z-score, 10. If a set of scores has a sample mean of 25 and a s...

10. If a set of scores has a sample mean of 25 and a sample variance of 4, find the following: a. the z-score for a raw score of 31 b. the z-score for a raw score of 18 c. the raw

Chi square test for more than two rows, Using Chi Square Test when more tha...

Using Chi Square Test when more than two Rows are Present   To understand this, let us consider the contingency table shown below. It gives us the information about the stage

Small sample test for mean, If the sample size is less than 30, then we nee...

If the sample size is less than 30, then we need to make the assumption that X (the volume of liquid in any cup) is normally distributed. This forces    (the mean volume in the sam

Coefficient of determination, Coefficient of Determination The c...

Coefficient of Determination The coefficient of determination is given by r 2 i.e., the square of the correlation coefficient. It explains to what extent the variation

Main effects and interactions, what is the independent variable in how ener...

what is the independent variable in how energetic do people feel after drinking different types of soft drints?

Displacement of a simply supported beam, The displacement of a simply suppo...

The displacement of a simply supported beam subject to a uniform load is given by the solution of the following differential equation (for small displacements); and q is th

Concepts of statistics, what are the importance, uses,optimums and applicat...

what are the importance, uses,optimums and applications of the following in agriculture field experiments; 1.standard deviation 2.standard error 3. coefficient of variation

Standard deviation for grouped data, Grouped data  For ...

Grouped data  For grouped data, the formula applied is  σ = Where f = frequency of the variable, μ= population mea

Local truncation error, (a) If one solves the ordinary differential equati...

(a) If one solves the ordinary differential equation using Euler's method find an expression for the local truncation error. (b) Using the result of (a) above what will

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