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

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.

Inverse cumulative distribution function, The Null Hypothesis - H0: β0 = ...

The Null Hypothesis - H0: β0 = 0, H0: β 1 = 0, H0: β 2 = 0, Β i = 0 The Alternative Hypothesis - H1: β0 ≠ 0, H0: β 1 ≠ 0, H0: β 2 ≠ 0, Β i ≠ 0      i =0, 1, 2, 3

Hypothesis testing, the president of a certain firm concerned about the saf...

the president of a certain firm concerned about the safety record of the firms employee sets aside $50 million a year for safety education. the firms accountant believes that more

Calculate the ratio of the sample standard deviation, The Case Study includ...

The Case Study included information about the price for a full meal before and after the law change (in dollars).  Of interest is whether the differences in price for a full meal b

Probability, HOW WOULD YOU INTERPRET THIS PROBABILITY:P(a)=1.05

HOW WOULD YOU INTERPRET THIS PROBABILITY:P(a)=1.05

Standard deviation , Standard Deviation  The concept of standard deviat...

Standard Deviation  The concept of standard deviation was first introduced by Karl Pearson in 1893. The standard deviation is the most important and the popular measure of disp

Help!, in a normal distribution with a mean of 85 and a STD of 5, what is t...

in a normal distribution with a mean of 85 and a STD of 5, what is the percentage of scores between 75 and 90?

Regression coefficient, Regression Coefficient While analysing regressi...

Regression Coefficient While analysing regression in two related series, we calculate their regression coefficients also. There are two regression coefficients like two regress

Empirical mode, Empirical Mode Where mode is ill-defined, its value may...

Empirical Mode Where mode is ill-defined, its value may be ascertained by the following formula based upon the empirical relationship between Mean, Median and Mode: Mode = 3

General algebraic and quantitative expressions, Read the following data on ...

Read the following data on the economy of Angoia and answer/respond to the questions/instructions that follow. Unless otherwise stated, the monetary figures are in real billions o

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