282 Lab 1

282: Lab 1

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── 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(palmerpenguins)

Question 1: I opened the preloaded data set trees.

trees_dat<-trees
head(trees)
  Girth Height Volume
1   8.3     70   10.3
2   8.6     65   10.3
3   8.8     63   10.2
4  10.5     72   16.4
5  10.7     81   18.8
6  10.8     83   19.7

Questions 2 and 3: I manipulated the initial trees data frame to include more

muttrees_dat<-(mutate(trees, diameter= trees$Girth/12))
muttrees_dat2<-(mutate(muttrees_dat, radius=muttrees_dat$diameter/2))
muttrees_dat2<-(mutate(muttrees_dat2, diainches=muttrees_dat2$diameter*12))

head(muttrees_dat2)
  Girth Height Volume  diameter    radius diainches
1   8.3     70   10.3 0.6916667 0.3458333       8.3
2   8.6     65   10.3 0.7166667 0.3583333       8.6
3   8.8     63   10.2 0.7333333 0.3666667       8.8
4  10.5     72   16.4 0.8750000 0.4375000      10.5
5  10.7     81   18.8 0.8916667 0.4458333      10.7
6  10.8     83   19.7 0.9000000 0.4500000      10.8

Question 4:

pens<-penguins
pens<-filter(penguins, species=='Adelie')
head(pens)
# A tibble: 6 × 8
  species island    bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
  <fct>   <fct>              <dbl>         <dbl>             <int>       <int>
1 Adelie  Torgersen           39.1          18.7               181        3750
2 Adelie  Torgersen           39.5          17.4               186        3800
3 Adelie  Torgersen           40.3          18                 195        3250
4 Adelie  Torgersen           NA            NA                  NA          NA
5 Adelie  Torgersen           36.7          19.3               193        3450
6 Adelie  Torgersen           39.3          20.6               190        3650
# ℹ 2 more variables: sex <fct>, year <int>

Question 5:

pens2<-filter(penguins, island=='Dream')
head(pens2)
# A tibble: 6 × 8
  species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
  <fct>   <fct>           <dbl>         <dbl>             <int>       <int>
1 Adelie  Dream            39.5          16.7               178        3250
2 Adelie  Dream            37.2          18.1               178        3900
3 Adelie  Dream            39.5          17.8               188        3300
4 Adelie  Dream            40.9          18.9               184        3900
5 Adelie  Dream            36.4          17                 195        3325
6 Adelie  Dream            39.2          21.1               196        4150
# ℹ 2 more variables: sex <fct>, year <int>

Question 6:

pens2<-pens2[,c(1,2,3)]
head(pens2)
# A tibble: 6 × 3
  species island bill_length_mm
  <fct>   <fct>           <dbl>
1 Adelie  Dream            39.5
2 Adelie  Dream            37.2
3 Adelie  Dream            39.5
4 Adelie  Dream            40.9
5 Adelie  Dream            36.4
6 Adelie  Dream            39.2

Question 7:

lobs<-Loblolly
head(lobs)
   height age Seed
1    4.51   3  301
15  10.89   5  301
29  28.72  10  301
43  41.74  15  301
57  52.70  20  301
71  60.92  25  301

Question 8:

widelobs<-lobs %>%
  pivot_wider(names_from=Seed, values_from=height)
head(widelobs)
# A tibble: 6 × 15
    age `301` `303` `305` `307` `309` `311` `315` `319` `321` `323` `325` `327`
  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1     3  4.51  4.55  4.79  3.91  4.81  3.88  4.32  4.57  3.77  4.33  4.38  4.12
2     5 10.9  10.9  11.4   9.48 11.2   9.4  10.4  10.6   9.03 10.8  10.5   9.92
3    10 28.7  29.1  30.2  25.7  28.7  26.0  27.2  27.9  25.4  29.0  27.9  26.5 
4    15 41.7  42.8  44.4  39.1  41.7  39.6  40.8  41.1  39.0  42.4  40.2  37.8 
5    20 52.7  53.9  55.8  50.8  53.3  51.5  51.3  52.4  49.8  53.2  50.1  48.4 
6    25 60.9  63.4  64.1  59.1  63.0  59.6  60.1  60.7  60.3  61.6  58.5  56.8 
# ℹ 2 more variables: `329` <dbl>, `331` <dbl>

Question 9:

longlobs<-widelobs %>%
  pivot_longer(!age, names_to = 'Seed', values_to = 'height')
head(longlobs)
# A tibble: 6 × 3
    age Seed  height
  <dbl> <chr>  <dbl>
1     3 301     4.51
2     3 303     4.55
3     3 305     4.79
4     3 307     3.91
5     3 309     4.81
6     3 311     3.88