install.packages(“tidyverse”) install.packages(“readxl”)
#Library
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.6
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.1 ✔ tibble 3.3.1
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.2
## ✔ purrr 1.2.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(readxl)
#Set Working Directory
setwd("~/Desktop/My Class Stuff/Monday Class")
#Data
cars_data <- read_csv("cars_data.csv")
## New names:
## Rows: 32 Columns: 12
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (1): ...1 dbl (11): mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `` -> `...1`
mpg <- cars_data$mpg
avg <- mean(mpg)
min <- min(mpg)
max <- max(mpg)
count <- length(mpg)
avg
## [1] 20.09062
min
## [1] 10.4
max
## [1] 33.9
count
## [1] 32
cat("average = ", avg, "\n")
## average = 20.09062
cat("minimum = ", min, "\n")
## minimum = 10.4
cat("maximum = ", max, "\n")
## maximum = 33.9
cat("number of cars = ", count)
## number of cars = 32