Consider themtcarsdata set which is available inR. Type the following code to explore the variables included in the data set (for an explanation of the variables see?mtcars:## Rows: 32## Columns: 11##...






Consider the
mtcars
data set which is available in
R
. Type the following code to explore the variables included in the data set (for an explanation of the variables see
?mtcars
:



## Rows: 32
## Columns: 11
## $ mpg 21.0, 21.0, 22.8, 21.4, 18.7, 18.1, 14.3, 24.4, 22.8, 19.2, 17.8,~ ##$cyl 6,6,4,6,8,6,8,4,4,6,6,8,8,8,8,8,8,4,4,4,4,8,~ ## $ disp 160.0, 160.0, 108.0, 258.0, 360.0, 225.0, 360.0, 146.7, 140.8, 16~ ## $ hp 110, 110, 93, 110, 175, 105, 245, 62, 95, 123, 123, 180, 180, 180~ ## $ drat 3.90, 3.90, 3.85, 3.08, 3.15, 2.76, 3.21, 3.69, 3.92, 3.92, 3.92,~ ## $ wt 2.620, 2.875, 2.320, 3.215, 3.440, 3.460, 3.570, 3.190, 3.150, 3.~ ## $ qsec 16.46, 17.02, 18.61, 19.44, 17.02, 20.22, 15.84, 20.00, 22.90, 18~ ##$vs 0,0,1,1,0,1,0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,~ ##$am 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,~ ## $ gear 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 4, 4, 4, 3, 3,~ ## $ carb 4, 4, 1, 1, 2, 1, 4, 2, 2, 4, 4, 3, 3, 3, 4, 4, 4, 1, 2, 1, 1, 2,~



Use the following code to create a new variable named
car_model
that contains the names of the cars, now available as row names.



## Rows: 32
## Columns: 12
## $ car_model "Mazda RX4", "Mazda RX4 Wag", "Datsun 710", "Hornet 4 Drive"~





page40image3000150848



library
(tidyverse)


glimpse
(mtcars)





page40image3000155344



mtcars

=

mtcars

%>%

rownames_to_column

(
"car_model"
)




glimpse
(mtcars)








## $ mpg
## $ cyl
## $ disp
## $ hp
## $ drat
## $ wt






21.0, 21.0, 22.8, 21.4, 18.7, 18.1, 14.3, 24.4, 22.8, 19.2, ~ 6,6,4,6,8,6,8,4,4,6,6,8,8,8,8,8,8,4,4,4,~ 160.0, 160.0, 108.0, 258.0, 360.0, 225.0, 360.0, 146.7, 140.~ 110, 110, 93, 110, 175, 105, 245, 62, 95, 123, 123, 180, 180~ 3.90, 3.90, 3.85, 3.08, 3.15, 2.76, 3.21, 3.69, 3.92, 3.92, ~ 2.620, 2.875, 2.320, 3.215, 3.440, 3.460, 3.570, 3.190, 3.15~









4.7. EXERCISES LAB 2
41







## $ qsec
## $ vs
## $ am
## $ gear
## $ carb






16.46, 17.02, 18.61, 19.44, 17.02, 20.22, 15.84, 20.00, 22.9~ 0,0,1,1,0,1,0,1,1,1,1,0,0,0,0,0,0,1,1,1,~ 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,~ 4,4,4,3,3,3,3,4,4,4,4,3,3,3,3,3,3,4,4,4,~ 4,4,1,1,2,1,4,2,2,4,4,3,3,3,4,4,4,1,2,1,~







Use the following code to define two factors for
cyl
and
am
which are now considered as
dbl
variables:





  1. How many observations and variables are available?





  2. Print (on the screen) the
    hp
    variable using the
    select()
    function. Try



    also to use the
    pull()
    function. Which is the difference?





  3. Print out all but the
    hp
    column using the
    select()
    function.





  4. Print out the following variables:
    mpg
    ,
    hp
    ,
    vs
    ,
    am
    ,
    gear
    . Suggestion: use
    :
    if necessary.





  5. Provide the frequency distribution (absolute and percentage) for the
    am
    variable (transmission).





  6. Select all the observations which have
    mpg>20
    and
    hp>100
    and compute the average for the
    mpg
    variable.





  7. Compute the distribution (absolute frequencies) of the car by
    gear
    . More- over, compute the mean consumption (
    mpg
    ) conditionally on the
    gear
    .






Oct 30, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here