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

Frequency distribution, mark number of student 0-10 4 10-20 8 ...

mark number of student 0-10 4 10-20 8 20-30 11 30-40 15 40-50 12 50-60 6 calculate frequency distribution

Bionomial, The Quality Manager of a battery manufacturing plant reviewed th...

The Quality Manager of a battery manufacturing plant reviewed the warranty records within his department and found that 4% of the low maintenance batteries produced at the plant ov

Median, The median, as the name suggests, is the middle value of a series a...

The median, as the name suggests, is the middle value of a series arranged in any of the orders of magnitude i.e. ascending or descending order. As distinct from the arithmetic

WEDGE FRICTION, Ask question #MinimumA wedge is small piece of material hav...

Ask question #MinimumA wedge is small piece of material having two of their opposite faces not parallel. To lift block of weight W, it is pushed by horizontal force P which lifts t

Introduction to probability, Introduction to Probability A ...

Introduction to Probability A student is considering whether she should enroll in an MBA educational program offered by a well-known college. Among othe

Regression Analysis, Question 3 25 marks Your employer, Quick Hit Agency ...

Question 3 25 marks Your employer, Quick Hit Agency (QHA), is a debt collections agency. The company specializes in collecting small accounts. QHA does not deal in large accounts

Spatial ability test, What would be the cutoff score to indicate a score th...

What would be the cutoff score to indicate a score that is in the top 15% of the scores on a test with a mean of 100 and a standard deviation of 15? This question has multiple p

Probability and expectation, Ten balls are put in 6 slots at random.Then ex...

Ten balls are put in 6 slots at random.Then expected total number of balls in the two extreme slots

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