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

..National Account- Descriptive Statistics, A country''s national accounts ...

A country''s national accounts are assumed to look as follows: GDP 1180 VAT and taxes 140 Commodity subsidies 60 Raw material and consumables 530 1. Calculate GVA 2. Calculate t

Determine the lower and upper fences, To study the physical fitness of a sa...

To study the physical fitness of a sample of 28 people, the data below was collected representing the  number of sit-ups that a person could do in one minute.      10    12

Statistics to support learning, Scenario: Many of the years 5 and year 6 l...

Scenario: Many of the years 5 and year 6 learners' at Woodlands Park School were excited about being chosen for the cross-country team.  Every day, they were able to run laps of t

Logistic regression model, A marketing research firm was engaged by an auto...

A marketing research firm was engaged by an automobile manufacturer to conduct a pilot study to examine the feasibility of using logistic regression for ascertaining the likelihood

Theoretical yield and actual yield, Write down the symbols and unit for the...

Write down the symbols and unit for the following: mass, molar mass, molar and molarity Write down the relationship between mass and molar mass and show that the units match.

Systematic sampling, Systematic Sampling In Systematic Sampling ...

Systematic Sampling In Systematic Sampling each element has an equal chance of being selected, but each sample does not have the same chance of being selected. Here,

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

Bionomial, The Quality Manager of a battery manufacturing plant reviewed th...

The Quality Manager of a battery manufacturing plant reviewed the warranty records within his department and found that 4% of the low maintenance batteries produced at the plant ov

Probability, 1 A penny is tossed 5 times. a. Find the chance that the 5th t...

1 A penny is tossed 5 times. a. Find the chance that the 5th toss is a head b. Find the chance that the 5th toss is a head, given the first 4 are tails.

Predict higpa using a logistic regression, In this problem, we use the CSDA...

In this problem, we use the CSDATA data set, which is available in 'CSDATA.txt'. We do ne an indicator variable, say HIGPA, to be 1 if the GPA is 3.0 or better and 0 other- wise. S

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