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

Correlation analysis, Correlation Analysis Correlation Analysis is perf...

Correlation Analysis Correlation Analysis is performed to measure the degree of association between two variables. The measure is called coefficient of correlation. The coeffic

Recitilinear motion, velocity of a particle which moves along the s-axis is...

velocity of a particle which moves along the s-axis is given by v=2-4t+5t then find position velocity,acceleration

Chi-square analysis, Chi-square analysis can be used with both Goodness-of-...

Chi-square analysis can be used with both Goodness-of-Fit Tests and with Tests for Independence. There are specific instances when each test should be used based on the information

Classical and modern regression, The data in the data frame asset are from ...

The data in the data frame asset are from Myers (1990), \Classical and Modern Regression with Applications (Second Edition)," Duxbury. The response y here is rm return on assets f

Limitations of arithmetic mean, The calculations of arithmetic mean m...

The calculations of arithmetic mean may be simple and foolproof, but the application of the result may not be so foolproof. An arithmetic mean may not merely lack

Chi square test, who invented the chi square test and why? what is central ...

who invented the chi square test and why? what is central chi square and non central chi square test? what is distribution free statistics? what are the conditions when the chi squ

Eigenvalue-based rules, Henry Kaiser suggested a rule for selecting a numbe...

Henry Kaiser suggested a rule for selecting a number of components m less than the number needed for perfect reconstruction: set m equal to the number of eigenvalues greater than I

Find probability of remaining paint free - ball duel, In a three-cornered p...

In a three-cornered paint ball duel, A, B, and C successively take shots at each other until only one of them remains paint free. Once hit, a player is out of the game and gets no

Multi stage or cluster random sampling, Multi stage or Cluster Random sampl...

Multi stage or Cluster Random sampling  Under this method, the random selection is made of primary, intermediate and final units from a given population. The area of investigat

Canonical correlation analysis, Canonical correlation analysis (CC) allows ...

Canonical correlation analysis (CC) allows the investigation of the relationship between two ,sets of variables. For example, a sociologist may want to investigate the Relationship

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