Lab 1 Assignment

Complete ALL of the essentials below correctly to earn an ‘S’ on the lab.
Complete the Depth portion successful to earn credit toward a depth boost (every 2 lab depth assignments completed earns a 1/3 letter grade boost to your final grade)

Render your document as a .pdf or .html and submit it to the google folder on Moodle for grading.

Essentials

1.) Opening this document confirms that you have a version of RStudio that is working! Try looking at the ‘visual’ tab to see what this document looks like when rendered and then render it and open the resulting file. This pipeline, which we call ‘render checking’ is really important! Render early, render often. When in doubt, render. Make sure your Quarto document is working after you make changes. /

2.) Set the working directory Use getwd() to find the working directory. Then use setwd() and the GUI to set the working directoy. Reminder: It is useful to have a folder for the course that you can use as your starting working directory when you load the RStudio Project for this class. Enter your getwd() and setwd() code in code chunk below

#Enter your getwd() code here
getwd()
[1] "/home/lohr22m/BIOL234"
#Enter your setwd() code here
setwd("~/BIOL234/")

Reminder: To insert a code chunk into Quarto you can use ctrl+alt+I (windows) or cmd+alt+I (Mac) OR click ‘+C’ in the top bar.

3.) Make an RStudio project for our class Name it whatever you’d like. I recommend “Biol234_Biostats” or something similar. Once it is done, take a screen shot of your RStudio screen and embed the image into below using the example code I have provided. It may also be helpful to make a folder on your server or computer for our class and use it as your working directory. /


4.) Load packages without error. Load tidyverse (our favorite and most versatile package) and palmerpenguins (which is just fun data) in the code chunk below

#load packages
library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.4.0      ✔ purrr   1.0.1 
✔ tibble  3.1.8      ✔ dplyr   1.0.10
✔ tidyr   1.3.0      ✔ stringr 1.5.0 
✔ readr   2.1.3      ✔ forcats 0.5.2 
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(palmerpenguins)

Question 5

5.) Basic data viewing - use the dataset mtcars as I did in the lab explanation. Use head(), tail(), str(), nrow(), ncol(), and then change a column from a number to a factor and from a factor back to a number. Confirm that each one of these actions works! Insert a code chunk below to begin.

Getting some information about the dataset

mtcars
                     mpg cyl  disp  hp drat    wt  qsec vs am gear carb
Mazda RX4           21.0   6 160.0 110 3.90 2.620 16.46  0  1    4    4
Mazda RX4 Wag       21.0   6 160.0 110 3.90 2.875 17.02  0  1    4    4
Datsun 710          22.8   4 108.0  93 3.85 2.320 18.61  1  1    4    1
Hornet 4 Drive      21.4   6 258.0 110 3.08 3.215 19.44  1  0    3    1
Hornet Sportabout   18.7   8 360.0 175 3.15 3.440 17.02  0  0    3    2
Valiant             18.1   6 225.0 105 2.76 3.460 20.22  1  0    3    1
Duster 360          14.3   8 360.0 245 3.21 3.570 15.84  0  0    3    4
Merc 240D           24.4   4 146.7  62 3.69 3.190 20.00  1  0    4    2
Merc 230            22.8   4 140.8  95 3.92 3.150 22.90  1  0    4    2
Merc 280            19.2   6 167.6 123 3.92 3.440 18.30  1  0    4    4
Merc 280C           17.8   6 167.6 123 3.92 3.440 18.90  1  0    4    4
Merc 450SE          16.4   8 275.8 180 3.07 4.070 17.40  0  0    3    3
Merc 450SL          17.3   8 275.8 180 3.07 3.730 17.60  0  0    3    3
Merc 450SLC         15.2   8 275.8 180 3.07 3.780 18.00  0  0    3    3
Cadillac Fleetwood  10.4   8 472.0 205 2.93 5.250 17.98  0  0    3    4
Lincoln Continental 10.4   8 460.0 215 3.00 5.424 17.82  0  0    3    4
Chrysler Imperial   14.7   8 440.0 230 3.23 5.345 17.42  0  0    3    4
Fiat 128            32.4   4  78.7  66 4.08 2.200 19.47  1  1    4    1
Honda Civic         30.4   4  75.7  52 4.93 1.615 18.52  1  1    4    2
Toyota Corolla      33.9   4  71.1  65 4.22 1.835 19.90  1  1    4    1
Toyota Corona       21.5   4 120.1  97 3.70 2.465 20.01  1  0    3    1
Dodge Challenger    15.5   8 318.0 150 2.76 3.520 16.87  0  0    3    2
AMC Javelin         15.2   8 304.0 150 3.15 3.435 17.30  0  0    3    2
Camaro Z28          13.3   8 350.0 245 3.73 3.840 15.41  0  0    3    4
Pontiac Firebird    19.2   8 400.0 175 3.08 3.845 17.05  0  0    3    2
Fiat X1-9           27.3   4  79.0  66 4.08 1.935 18.90  1  1    4    1
Porsche 914-2       26.0   4 120.3  91 4.43 2.140 16.70  0  1    5    2
Lotus Europa        30.4   4  95.1 113 3.77 1.513 16.90  1  1    5    2
Ford Pantera L      15.8   8 351.0 264 4.22 3.170 14.50  0  1    5    4
Ferrari Dino        19.7   6 145.0 175 3.62 2.770 15.50  0  1    5    6
Maserati Bora       15.0   8 301.0 335 3.54 3.570 14.60  0  1    5    8
Volvo 142E          21.4   4 121.0 109 4.11 2.780 18.60  1  1    4    2
mtcars2 <- mtcars
#top 6 rows#
head(mtcars2)
                   mpg cyl disp  hp drat    wt  qsec vs am gear carb
Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1
#last 6 rows#
tail(mtcars2)
                mpg cyl  disp  hp drat    wt qsec vs am gear carb
Porsche 914-2  26.0   4 120.3  91 4.43 2.140 16.7  0  1    5    2
Lotus Europa   30.4   4  95.1 113 3.77 1.513 16.9  1  1    5    2
Ford Pantera L 15.8   8 351.0 264 4.22 3.170 14.5  0  1    5    4
Ferrari Dino   19.7   6 145.0 175 3.62 2.770 15.5  0  1    5    6
Maserati Bora  15.0   8 301.0 335 3.54 3.570 14.6  0  1    5    8
Volvo 142E     21.4   4 121.0 109 4.11 2.780 18.6  1  1    4    2
#column attributes#
str(mtcars2)
'data.frame':   32 obs. of  11 variables:
 $ mpg : num  21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
 $ cyl : num  6 6 4 6 8 6 8 4 4 6 ...
 $ disp: num  160 160 108 258 360 ...
 $ hp  : num  110 110 93 110 175 105 245 62 95 123 ...
 $ drat: num  3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...
 $ wt  : num  2.62 2.88 2.32 3.21 3.44 ...
 $ qsec: num  16.5 17 18.6 19.4 17 ...
 $ vs  : num  0 0 1 1 0 1 0 1 1 1 ...
 $ am  : num  1 1 1 0 0 0 0 0 0 0 ...
 $ gear: num  4 4 4 3 3 3 3 4 4 4 ...
 $ carb: num  4 4 1 1 2 1 4 2 2 4 ...
#number of rows#
nrow(mtcars2)
[1] 32
#number of columns#
ncol(mtcars2)
[1] 11

Manipulating the data

#change mpg from num to factor#
mtcars2$mpg=as.factor(mtcars2$mpg)
str(mtcars2$mpg)
 Factor w/ 25 levels "10.4","13.3",..: 16 16 19 17 13 12 3 20 19 14 ...

Changing the data back to how it was

#change mpg back to num attempt 1 did not work#
mtcars2$mpg=as.numeric(mtcars2$mpg)
str(mtcars2$mpg)
 num [1:32] 16 16 19 17 13 12 3 20 19 14 ...
#Attempt 2 worked better, thank you Google#
mtcars2$mpg <- as.numeric(as.character(mtcars2$mpg))
str(mtcars2$mpg)
 num [1:32] 16 16 19 17 13 12 3 20 19 14 ...

Depth

1.) Make a directory (folder) for our class, set is as the wd for your project and then add the following folders within the directory: data, code, labs. Screenshot this folder and insert the image into your Quarto report below

2.) Do basic data viewing on the penguins dataset from the palmerpenguins package. This includes head(), tail(), str(), nrow(), ncol(), and changing column attributes (as in Essentials #5). CONFIRM that all work! Insert a code chunk below to begin

# double set of :: to open specific dataset from a library?#
palmerpenguins::penguins
# A tibble: 344 × 8
   species island    bill_length_mm bill_depth_mm flipper_…¹ body_…² sex    year
   <fct>   <fct>              <dbl>         <dbl>      <int>   <int> <fct> <int>
 1 Adelie  Torgersen           39.1          18.7        181    3750 male   2007
 2 Adelie  Torgersen           39.5          17.4        186    3800 fema…  2007
 3 Adelie  Torgersen           40.3          18          195    3250 fema…  2007
 4 Adelie  Torgersen           NA            NA           NA      NA <NA>   2007
 5 Adelie  Torgersen           36.7          19.3        193    3450 fema…  2007
 6 Adelie  Torgersen           39.3          20.6        190    3650 male   2007
 7 Adelie  Torgersen           38.9          17.8        181    3625 fema…  2007
 8 Adelie  Torgersen           39.2          19.6        195    4675 male   2007
 9 Adelie  Torgersen           34.1          18.1        193    3475 <NA>   2007
10 Adelie  Torgersen           42            20.2        190    4250 <NA>   2007
# … with 334 more rows, and abbreviated variable names ¹​flipper_length_mm,
#   ²​body_mass_g
data(penguins)
penguindepth <- penguins
head(penguindepth)
# A tibble: 6 × 8
  species island    bill_length_mm bill_depth_mm flipper_l…¹ body_…² sex    year
  <fct>   <fct>              <dbl>         <dbl>       <int>   <int> <fct> <int>
1 Adelie  Torgersen           39.1          18.7         181    3750 male   2007
2 Adelie  Torgersen           39.5          17.4         186    3800 fema…  2007
3 Adelie  Torgersen           40.3          18           195    3250 fema…  2007
4 Adelie  Torgersen           NA            NA            NA      NA <NA>   2007
5 Adelie  Torgersen           36.7          19.3         193    3450 fema…  2007
6 Adelie  Torgersen           39.3          20.6         190    3650 male   2007
# … with abbreviated variable names ¹​flipper_length_mm, ²​body_mass_g
tail(penguindepth)
# A tibble: 6 × 8
  species   island bill_length_mm bill_depth_mm flipper_le…¹ body_…² sex    year
  <fct>     <fct>           <dbl>         <dbl>        <int>   <int> <fct> <int>
1 Chinstrap Dream            45.7          17            195    3650 fema…  2009
2 Chinstrap Dream            55.8          19.8          207    4000 male   2009
3 Chinstrap Dream            43.5          18.1          202    3400 fema…  2009
4 Chinstrap Dream            49.6          18.2          193    3775 male   2009
5 Chinstrap Dream            50.8          19            210    4100 male   2009
6 Chinstrap Dream            50.2          18.7          198    3775 fema…  2009
# … with abbreviated variable names ¹​flipper_length_mm, ²​body_mass_g
str(penguindepth)
tibble [344 × 8] (S3: tbl_df/tbl/data.frame)
 $ species          : Factor w/ 3 levels "Adelie","Chinstrap",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ island           : Factor w/ 3 levels "Biscoe","Dream",..: 3 3 3 3 3 3 3 3 3 3 ...
 $ bill_length_mm   : num [1:344] 39.1 39.5 40.3 NA 36.7 39.3 38.9 39.2 34.1 42 ...
 $ bill_depth_mm    : num [1:344] 18.7 17.4 18 NA 19.3 20.6 17.8 19.6 18.1 20.2 ...
 $ flipper_length_mm: int [1:344] 181 186 195 NA 193 190 181 195 193 190 ...
 $ body_mass_g      : int [1:344] 3750 3800 3250 NA 3450 3650 3625 4675 3475 4250 ...
 $ sex              : Factor w/ 2 levels "female","male": 2 1 1 NA 1 2 1 2 NA NA ...
 $ year             : int [1:344] 2007 2007 2007 2007 2007 2007 2007 2007 2007 2007 ...
nrow(penguindepth)
[1] 344
ncol(penguindepth)
[1] 8
penguindepth$bill_depth_mm<-as.factor(penguindepth$bill_depth_mm)
str(penguindepth$bill_depth_mm)
 Factor w/ 80 levels "13.1","13.2",..: 57 44 50 NA 63 75 48 66 51 72 ...
penguindepth$bill_depth_mm<-as.numeric(as.character(penguindepth$bill_depth_mm))
str(penguindepth$bill_depth_mm)
 num [1:344] 18.7 17.4 18 NA 19.3 20.6 17.8 19.6 18.1 20.2 ...

3.) Reformat this document to add headers (heading level 1 and 2 at least!), change formatting of text in other ways. Make at least 3 types of change and document them below (you can just type our text of what you did). The formatting changes should show up as visual differences in your final report! When you are done, you can turn in your assignment on Moodle (using the google form)

\ I put ellipsis around the first header for fun hehe. I made the Depth header Header 2 rather than Header 1 in size by adding an extra pound sign. Last, I put some smaller headers in italics on question 5 to organize it a bit.