Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose in R, we have a vector of real numbers x. Write R code to divide x up into 3 equally spaced bins, and count

Suppose in R, we have a vector of real numbers x. Write R code to divide x up into 3 equally spaced bins, and count the number of elements of x that lie in each bin, and store these counts in a vector y (i.e., y should have three elements: the first element should be the count for the first bin, and the second element should be the count for the second bin, and so on). The first bin should have left extent given by the minimum value of x and the last bin should have right extent given by the maximum value of x. The bins must exclude their left end-point, and include their right end-point. Provide your code, and also create 2 small examples (versions of x) using any values you like, demonstrating that the lines of code meet the requirements.

Extend the code you wrote for the above problem by making a function in R called count. The function should take a vector of real numbers x and a positive integer n. The function divide x into n equally spaced bins, and count how many elements of x are in each bin (as above, but for n instead of 3 bins). The function should return a vector of length n containing the counts.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

International Auditing Standards In The United States Comparing And Understanding Standards For ISA And PCAOB

Authors: Asokan Anandarajan, Gary Kleinman

2nd Edition

1953349323, 9781953349323

More Books

Students also viewed these Accounting questions

Question

What is the average age of members of your key public?

Answered: 1 week ago

Question

How likely is this public to act on information it receives?

Answered: 1 week ago

Question

What does this public think about your organization?

Answered: 1 week ago