Conceptual Questions

  1. An R package is a collection of functions and data that pertain to a certain topic. Install.packages downloads packages to your computer while library reads in the package so you have access to it in your R session.

  2. We use the str() function on R objects to determine what type of object we are working with.

  3. A named list in a one-dimensional object where each element in the list has a name.

  4. A delimiter is a character that separates data values in a raw data file.

Reading in Raw Data and Manipulating Data Frames

library(readxl)
#reads the readxl package into the R session
car <- read_excel("C:/Users/lukeb/Downloads/CarDepreciation.xlsx")
#reads the excel file and stores it as and R object car
car[, c(1,4)]
## # A tibble: 20 × 2
##    Car                   Depreciation
##    <chr>                        <dbl>
##  1 Mazda3                        2630
##  2 Buick Encore                  2135
##  3 Toyota Corolla                1330
##  4 Chrevolet Tahoe               2026
##  5 Chrevolet Equinox             2447
##  6 Ford Fiesta                   2026
##  7 BMW 528i                      1645
##  8 Mitsubishi Mirage             2410
##  9 GMC Yukon                     1660
## 10 Dodge Dart                    2259
## 11 Honda Accord Hybrid           2116
## 12 Audi Q5                       1942
## 13 Hyundai Elantra               1931
## 14 Kia Sedona                    3532
## 15 Dodge Grand Caravan           3947
## 16 Lexus CT                      3561
## 17 Lincoln MKZ Hybrid            2630
## 18 Mercedez-Benz E-Class         4222
## 19 Scion tC                      1051
## 20 MINI Countryman               1617
#subsets the data to only return the car and depreciation columns
car[order(car$Depreciation,decreasing =  F), c(1,4)]
## # A tibble: 20 × 2
##    Car                   Depreciation
##    <chr>                        <dbl>
##  1 Scion tC                      1051
##  2 Toyota Corolla                1330
##  3 MINI Countryman               1617
##  4 BMW 528i                      1645
##  5 GMC Yukon                     1660
##  6 Hyundai Elantra               1931
##  7 Audi Q5                       1942
##  8 Chrevolet Tahoe               2026
##  9 Ford Fiesta                   2026
## 10 Honda Accord Hybrid           2116
## 11 Buick Encore                  2135
## 12 Dodge Dart                    2259
## 13 Mitsubishi Mirage             2410
## 14 Chrevolet Equinox             2447
## 15 Mazda3                        2630
## 16 Lincoln MKZ Hybrid            2630
## 17 Kia Sedona                    3532
## 18 Lexus CT                      3561
## 19 Dodge Grand Caravan           3947
## 20 Mercedez-Benz E-Class         4222
#subsets the data to only return the car and depreciation columns as well as indexing the rows by depreciation value from smallest to largest
x <- "https://www4.stat.ncsu.edu/~online/datasets/Cereal.csv"
# saves the url as the variable x
cols <- c("Name", "Company", "Serving", "Calories", "Fat", "Sodium", "Carbs", "Fiber", "Sugars", "Protein")
#creates a character vector with the names
cereal <- read.csv(x, col.names = cols)
#saves the file with the new names as an R object cereal
cereal
##                     Name Company Serving Calories Fat Sodium Carbs Fiber Sugars
## 1              Boo Berry       G    1.00      118 0.8    211    27   0.1   14.0
## 2           Cap'n Crunch       Q    0.75      144 2.1    269    31   1.1   16.0
## 3  Cinnamon Toast Crunch       G    0.75      169 4.4    408    32   1.7   13.3
## 4           Cocoa Blasts       Q    1.00      130 1.2    135    29   0.8   16.0
## 5            Cocoa Puffs       G    1.00      117 1.0    171    26   0.8   14.0
## 6           Cookie Crisp       G    1.00      117 0.9    178    26   0.5   13.0
## 7            Corn Flakes       K    1.00      101 0.1    202    24   0.8    3.0
## 8              Corn Pops       K    1.00      117 0.2    120    28   0.3   15.0
## 9                Crispix       K    1.00      113 0.3    229    26   0.1    3.0
## 10          Crunchy Bran       Q    0.75      120 1.3    309    31   6.4    8.0
## 11           Froot Loops       K    1.00      118 0.9    150    26   0.8   12.0
## 12   Frosted Mini-Wheats       K    1.00      175 0.8      5    41   5.0   10.0
## 13        Golden Grahams       G    0.75      149 1.3    359    33   1.3   14.7
## 14    Honey Nut Clusters       G    1.00      214 2.7    249    46   2.8   17.0
## 15      Honey Nut Heaven       Q    1.00      192 3.7    216    38   3.5   13.0
## 16          King Vitaman       Q    1.50       80 0.7    173    17   0.9    4.0
## 17                   Kix       G    1.30       87 0.5    205    20   0.8    2.3
## 18                  Life       Q    0.75      160 1.9    219    33   2.7    8.0
## 19          Lucky Charms       G    1.00      114 1.1    203    25   1.5   13.0
## 20  Multi-Grain Cheerios       G    1.00      108 1.2    201    24   2.8    6.0
## 21            Product 19       K    1.00      100 0.4    207    25   1.0    4.0
## 22           Raisin Bran       K    1.00      195 1.6    362    47   7.3   20.0
## 23         Reese's Puffs       G    0.75      171 3.9    223    31   0.0   16.0
## 24             Rice Chex       G    1.25       94 0.2    234    22   0.1    1.6
## 25   Rice Krispie Treats       K    0.75      160 1.7    252    35   0.0   12.0
## 26           Smart Start       K    1.00      182 0.7    275    43   2.8   14.0
## 27             Special K       K    1.00      117 0.4    224    22   0.8    4.0
## 28                 Total       G    0.75      129 0.9    256    31   3.7    6.7
## 29              Wheaties       G    1.00      107 1.0    218    24   3.0    4.0
##    Protein
## 1      1.0
## 2      1.3
## 3      2.7
## 4      1.0
## 5      1.0
## 6      1.0
## 7      2.0
## 8      1.0
## 9      2.0
## 10     1.3
## 11     2.0
## 12     5.0
## 13     2.7
## 14     4.0
## 15     4.0
## 16     1.3
## 17     1.5
## 18     4.0
## 19     2.0
## 20     2.0
## 21     2.0
## 22     5.0
## 23     2.7
## 24     1.6
## 25     1.3
## 26     4.0
## 27     7.0
## 28     4.0
## 29     3.0

Open-Ended

  1. I am majoring in business administration with a concentration in finance. In my future career, I will interact with data to determine revenues and sales of products in a product line. This information can then be communicated to decision makers.

  2. url for where I found my data set: https://catalog.data.gov/dataset/fdic-failed-bank-list/resource/a8cfc40d-bf6d-4716-bba6-04fdbdf5f9c1 url for the data set: https://www.fdic.gov/bank/individual/failed/banklist.csv I chose this data set because I will be working in the finance industry. This data set contains bank failures in the United States. Working with banks is one possible option for me in a future career. This is why I found the data set Interesting.

banklist <- read_excel("C:/Users/lukeb/Downloads/banklist.xlsx")
#reads in the data set from excel and saves it as an R object banklist
banklist
## # A tibble: 567 × 7
##    `Bank Name `                  `City ` `State ` `Cert ` Acquiring Institutio…¹
##    <chr>                         <chr>   <chr>      <dbl> <chr>                 
##  1 Heartland Tri-State Bank      Elkhart KS         25851 Dream First Bank, N.A.
##  2 First Republic Bank           San Fr… CA         59017 JPMorgan Chase Bank, …
##  3 Signature Bank                New Yo… NY         57053 Flagstar Bank, N.A.   
##  4 Silicon Valley Bank           Santa … CA         24735 First–Citizens Bank &…
##  5 Almena State Bank             Almena  KS         15426 Equity Bank           
##  6 First City Bank of Florida    Fort W… FL         16748 United Fidelity Bank,…
##  7 The First State Bank          Barbou… WV         14361 MVB Bank, Inc.        
##  8 Ericson State Bank            Ericson NE         18265 Farmers and Merchants…
##  9 City National Bank of New Je… Newark  NJ         21111 Industrial Bank       
## 10 Resolute Bank                 Maumee  OH         58317 Buckeye State Bank    
## # ℹ 557 more rows
## # ℹ abbreviated name: ¹​`Acquiring Institution `
## # ℹ 2 more variables: `Closing Date ` <dttm>, Fund <dbl>