Question
Stuck on writing a function in R # First, let's write a function `get_col_info()` that takes as parameters a # column name and a dataframe.
Stuck on writing a function in R
# First, let's write a function `get_col_info()` that takes as parameters a # column name and a dataframe. If the values in the column are *numeric*, # the function should return a list with the keys: # - `min`: the minimum value of the column # - `max`: the maximum value of the column # - `mean`: the mean value of the column # If the column is *not* numeric and there are fewer than 10 unique values in # the column, you should return a list with the keys: # - `n_values`: the number of unique values in the column # - `unique_values`: a vector of each unique value in the column # If the column is *not* numeric and there are 10 or *more* unique values in # the column, you should return a list with the keys: # - `n_values`: the number of unique values in the column # - `sample_values`: a vector containing a random sample of 10 column values # Hint: use `typeof()` to determine the column type
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started