Question: 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

This is a R program Problem 2 Create an empty vector mpg_discrete

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 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!