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

Demand, A monopolist firm''s demand curve is given by P:100-2q. (a) Find it...

A monopolist firm''s demand curve is given by P:100-2q. (a) Find its marginal revenue function.

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

Factor loadings matrix, As we stated above, we start factor analysis with p...

As we stated above, we start factor analysis with principal component analysis, but we quickly diverge as we apply the a priori knowledge we brought to the problem. This knowled

The incidence of occupational disease , The incidence of occupational disea...

The incidence of occupational disease in an industry is such that the workers have a 20% chance of suffering from it. What is the probability that out of six workers 4 or more will

Compare the t interval with the bootstrap interval, Jocko's Garage has been...

Jocko's Garage has been accused of insurance fraud. Data on estimates made by Jocko and another garage were obtained for 10 damaged vehicles (available in 'jockogarage.txt'). Here

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

Simple linear regression model, A study was conducted to determine the amou...

A study was conducted to determine the amount of heat loss for a certain brand of thermal pane window. Three different windows were randomly subjected to each of three different ou

Define the term multicollinearity, Question: (a) (i) Define the term ...

Question: (a) (i) Define the term multicollinearity. (ii) Explain why it is important to guard against multicollinearity. (b) (i) Sometimes we encounter missing values

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