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

Statistics assignment, Need statistic assignment help. Need by Monday, 26Th...

Need statistic assignment help. Need by Monday, 26Th May. Gretl has to be used compulsory.

Statistical inquiry, Main stages of Statistical Inquiry The following a...

Main stages of Statistical Inquiry The following are the various stages of a statistical inquiry (1)   Planning the Inquiry: First of all we have to assess the problem und

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,

Compute the sample mean and sample standard deviation, We want to investiga...

We want to investigate the income data.  In the Excel file Midterm  Data.xls there is a tab labeled "Income Data 2006".  The data in the tab is the income reported by 400 people in

Draw a network diagram for this problem, The project of building a backyard...

The project of building a backyard swimming pool consists of eight major activities and has to be completed within 19 weeks. The activities and related data are given in the follow

Determine the matrix of the transformation, Consider the linear transformat...

Consider the linear transformation (a) Find the image of (3 , -2 , 2) under T. (b) Does the vector (5, 3) belong to the range of T? (c) Determine the matrix of the transf

Liner programming , Solve the following Linear Programming Problem using S...

Solve the following Linear Programming Problem using Simple method. Maximize Z= 3x1 + 2X2 Subject to the constraints: X1+ X2 = 4 X1 - X2 = 2 X1, X2 = 0

Write out the estimator of the linear combination, Now, let's look at a dif...

Now, let's look at a different linear combination. Suppose we are interested n comparing the average mean log income for no college education ( 16). 1. Write out the linear com

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