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

Graphical calculation for mode, For calculating the mode of the grouped dat...

For calculating the mode of the grouped data graphically, the following procedure is adopted. Draw a histogram of the data; the modal class is the tallest rectangle.

Descriptive statistics, Descriptive Statistics : Carrying out an extens...

Descriptive Statistics : Carrying out an extensive analysis the data was not a subject to ambiguity and there were no missing values.  Below are descriptive statistics that hav

Find the probability that a lift will weigh, Lifts usually have signs indic...

Lifts usually have signs indicating their maximum capacity. Consider a sign in a lift that reads "maximum capacity 1400kg or 20 persons". Suppose that the weights of lift-users are

Coefficient of variation, Coefficient of Variation The standard dev...

Coefficient of Variation The standard deviation discussed above is an absolute measure of dispersion. The corresponding relative measure is known as the coefficient of vari

Stata question, i am new to stata and i am trying to figure out how to calc...

i am new to stata and i am trying to figure out how to calculate expected growth of sales tax revenue as well as average growth rate of sales tax revenue in stata. I have a dataset

QUARTILE DEVIATION, Examples of grouped, simple and frequency distribution ...

Examples of grouped, simple and frequency distribution data

Calculate the mle estimate for mean, Each section of the SAT test is suppos...

Each section of the SAT test is supposed to be distributed normally with a mean of 500 and a standard deviation of 100. Suppose 5 students in a class took the SAT math test. They r

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

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

Significance of correlation, Significance of Correlation The study of c...

Significance of Correlation The study of correlation is of immense use in practical life. Correlation analysis contributes to the understanding of economic behavior, aids in lo

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