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

Index number, Index Number Meaning and Definitions of Index Number ...

Index Number Meaning and Definitions of Index Number The index numbers are the special type of averages which are presented in percentages and computed on certain base.

Determine probability that the person tested has the disease, There are two...

There are two diagnostic tests for a disease. Among those who have the disease, 10% give negative results on the first test, and independently of this, 5% give negative results on

Chi-square test, Consider the following linear regression model:      a)...

Consider the following linear regression model:      a) What does y and x 1 , x 2 , . . . . x k represent?      b) What does β o , β 1 , β 2 , . . . . β k represent?

Determine how the ordinary least squares, Question Following the general...

Question Following the general methodology used by econometricians as explained in the session for week 1 (eight steps), explain how you would proceed to determine if a good com

Stat, solve problems

solve problems

Median for ungrouped data, If the data set contains an odd number of items,...

If the data set contains an odd number of items, the middle item of the array is the median. If there is an even number of items, the median is the average of the two items. If the

Determine relative frequency, A sample of college students and a separate s...

A sample of college students and a separate sample of adults aged 30-59 were surveyed regarding the amount of fruit they eat each day.  The results are shown in the histograms belo

Cluster analysis, Cluster Analysis could be also represented more formally ...

Cluster Analysis could be also represented more formally as optimization procedure, which tries to minimize the Residual Sum of Squares objective function: where μ(ωk) - is a centr

Poisson distribution, Poisson Distribution The poisson Distribution  wa...

Poisson Distribution The poisson Distribution  was discovered  by French mathematician simon  denis  poisson. It is a discrete probability distribution. Meaning : In bi

Discriminant analysis, Discriminant analysis (DA) helps to determine which ...

Discriminant analysis (DA) helps to determine which variables discriminate between two or more naturally occurring groups. Mathematically equivalent to MANOVA, it ' is extensively

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