Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3 Functions and control flows a. Write an R function called descr_stats that, given a data frame, returns the number of missing values per each

image text in transcribed
3 Functions and control flows a. Write an R function called descr_stats that, given a data frame, returns the number of missing values per each variable, the mean and the sample variance for all the numeric variables, and the most frequent value for the categorical variables (8 points). Feel free to use the mean() and var() functions which are available in base R. By categorical I mean factor or character vectors. Make sure that the mean and the sample variance do not return NA . The function should return a list of three elements: - the first element is an atomic vector containing integers which represent the number of missing values in each variable. The length of this vector must be equal to the number of variables in the data frame. Add names to the elements of the vector for better readability (1 point). - The second element is a matrix containing as many rows as the number of numeric variables in the data frame, and two columns. The rst column should contain the mean and the second column the sample variance. Add names to rows and columns for better readability (2 points). - The third element is a character vector containing the most frequent value of each categorical variable. Add names to the elements of the vector for better readability (1 point). b. Import countypop dataset (from Homework 1) and apply the function on that dataset to test that the function works (4 points)

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

Recent Developments Of Mathematical Fluid Mechanics

Authors: Herbert Amann, Yoshikazu Giga, Hideo Kozono, Hisashi Okamoto, Masao Yamazaki

1st Edition

3034809395, 9783034809399

More Books

Students also viewed these Mathematics questions

Question

List the key components within occupational health and safety.

Answered: 1 week ago

Question

Identify the general types of employment laws in Canada.

Answered: 1 week ago

Question

Describe discrimination and harassment in the workplace.

Answered: 1 week ago