Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is a R program Problem 2 Create an empty vector mpg_discrete with length equal to the number of rows in mtcars dataset. Write a
This is a R program
Problem 2 Create an empty vector mpg_discrete with length equal to the number of rows in mtcars dataset. Write a for loop to iterate i from 1 to the length of rows in mtcars dataset. Assign 0 to mpg_discrete[i] if the ith mpg is larger or equal than its mean; Assign 1 to mpg_discreteiif the ith mpg is smaller than its mean. Problem 3 Use apply function to avoid a for loop in problem 2 and create the same output. Tips: write a customized function with input as a row vector and output as the converted mpg, i.e., 0 or 1Step 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