Question: Can you compute the descriptive statistics for all the numerical variables in the data without repeating your code for each variable? HINT: You can use
Can you compute the descriptive statistics for all the numerical variables in the data without repeating your code for each variable? HINT: You can use functions like lapply() or sapply() in R to do this. Optional Bonus Question (+2 points) Can you create a function that takes two inputs: input_data (a dataframe) and id (a column name). Here are some helpful hints: The goal of the function is to compute the descriptive statistics (mean, median, min, max) for the variable in the column id of the dataframe input_data if the column is numeric or integer. Use the IF function inside the function to check if the class is integer or numeric Example code: if(class(input_data[,id]) == "numeric" | class(input_data[,id]) == "integer") Create a DataFrame called summary within the function that has the required columns (variable, mean, median, min, max). Each column takes the appropriate value (e.g., mean(input_data[,id]) will give you the mean of column id in the input_data). The function should return the summary DataFrame Example code: return(summary) Invoke the function you created for the variable time_since_release (Hint: use the column id to call the function). Save the output of the function to a new variable named output_data
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
