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

Expected average time, Question: A car was machine washes each car in 5 min...

Question: A car was machine washes each car in 5 minutes exactly. It has been estimated that customers will arrive according to a Poisson distribution at an average of 8 per hour.

Enumerate the set, Grid is the set of pairs {1, 2, 3, 4} x {1, 2, 3, 4}. ...

Grid is the set of pairs {1, 2, 3, 4} x {1, 2, 3, 4}. Image is the power set of Grid. An element of Image is a subset of Grid and can be represented by a diagram on a 4 by 4

Dispersion.., discuss the advantages and disadvantages of measures of dispe...

discuss the advantages and disadvantages of measures of dispersions

HLT 362, What is an interaction? Describe an example and identify the varia...

What is an interaction? Describe an example and identify the variables within your population (work, social, academic, etc.) for which you might expect interactions?

Conduct a hypothesis testing, Celia is a nurse in a geriatric ward.  She no...

Celia is a nurse in a geriatric ward.  She noticed that older persons in her care are having problems sleeping at night.  She decided to introduce non-pharmocologic ways of relaxat

Use event rule ot estimates the claim, Make a decision about the given clai...

Make a decision about the given claim. Use only the rare event rule, and make subjective estimates to determine whether events are likely. For example, if the claim is that a coi

Simple linear regression, We are interested in assessing the effects of tem...

We are interested in assessing the effects of temperature (low, medium, and high) and technical configuration on the amount of waste output for a manufacturing plant. Suppose that

Show the hypothesis test, The file Midterm Data.xls has a tab labeled "Inc...

The file Midterm Data.xls has a tab labeled "Income Data 2009". This data is collected income data from a sample of 400 people in 2009. Use a hypothesis test to see whether the av

Control chart, construction of control chart,n chart

construction of control chart,n chart

Problem set for logistic regression, (1) What values can the response varia...

(1) What values can the response variable Y take in logistic regression, and hence what statistical distribution does Y follow? The response variable can take the value of either

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