Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. In R, execute the following code: data(mtcars) mpg

1. In R, execute the following code:
data(mtcars)
mpg <- array(mtcars$mpg, c(4,8))
Then answer the following questions:
a) What is the datatype of the mpg array that you have created? How do you know?
b) What happens to the values in mpg if you pass it through the as.integer() function? What happens to the shape?
c) What is a statement that you can write to find the value in the 2nd row and 7th column of mpg? What is that value?
d) Using only indexing and assignment, what statement can you write to create a 4x4 matrix named mpg.subset containing the values in the 1st, 4th, 5th, and 8th columns and first four (4) rows of mpg?
e) What statement can you write to find the average value in mpg? What is the average value?
f) What statement can you write to change the value in the 4th row and 5th column of mpg to the average value you found in part e)? By how much does the average value change when you do this?

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_2

Step: 3

blur-text-image_3

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions