Answered step by step
Verified Expert Solution
Link Copied!

Question

00
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 with AI-Powered 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

Students also viewed these Accounting questions