Statistics homework help

Q1) A) 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 4 small examples (versions of x) using any values you

like, demonstrating that the lines of code meet the requirements.

B) 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.