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

SPSS Program, I have 5 observations that i must plug into spss. I need an e...

I have 5 observations that i must plug into spss. I need an example of 1. I do not know if you are familiar with SPSS but I am going to ask anyway. Subject 1 is a Hispanic male who

Median, introduction of median

introduction of median

Compute the standard deviation, Let X, Y, and Z refer to the three random v...

Let X, Y, and Z refer to the three random variables. It is known that Var(X) = 4, Var(Y) = 9, and Var(Z) = 16. It is further known that E(X) = 1, E(Y) = 2, and E(Z) = 4. Furthermor

Decision theory, 1. Definition of decision tree, 2. Feature of decision the...

1. Definition of decision tree, 2. Feature of decision theory problem

Sequential sampling, Sequential Sampling Under this method, a number of...

Sequential Sampling Under this method, a number of sample lots are drawn one after another from a universe depending on the results of the earlier samples. Such sampling is gen

the npv of the book , Bill Clinton reportedly was paid $10 million to writ...

Bill Clinton reportedly was paid $10 million to write his book My Way. The book took three years to write. In the time he spent writing, Clinton could have been paid to make speech

Hypothesistesting, Apl.send me nots on hypothesis testing sk question #Mi...

Apl.send me nots on hypothesis testing sk question #Minimum 100 words accepted#

Construct a cumulative percentage polygon, 1. For each of the following var...

1. For each of the following variables: major, graduate GPA, and height: a. Determine whether the variable is categorical or numerical. b. If the variable is numerical, deter

What are the coefficients of the linear combination, For the following ques...

For the following questions we are interested in a comparison of the 16 years education vs. > 16 years. (Recall we did the analysis on the log scale, so these are actual means on t

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