Hello world

Here is some new text. This word is red.

If you want it to update, you need to knit it and then click Republish at the top right.

One ‘#’ is heading one, two ‘##’ is heading two, you need to leave a space. Up to 6.

Heading one

Heading two

italic

bold

bold and italic

  • bullet
  • bullet
  1. test
  2. test
  3. test

a link

print("Hello world")
## [1] "Hello world"

Some more text

And then another code chunk

result <- 5 * 3
print(result)
## [1] 15

using the funny quotes like this formats something as if its code print("hi") okay

I don’t think it actually runs it though

plot(iris$Sepal.Length ~ iris$Species)

Learning

from this youtube video

Square brackets index, for example:

vect <- c(0, 5, 7, NA, 3, 45, 0.2)
vect[!is.na(vect)]
## [1]  0.0  5.0  7.0  3.0 45.0  0.2

Seq creates a vector of values that increment at a regular rate from (start) to (finish) and by (interval)

rep repeats things

grepl finds a string of text within a vector

seq(from = 3, to = 30, by = 6)
## [1]  3  9 15 21 27
rep(x = 1:3, times = 3)
## [1] 1 2 3 1 2 3 1 2 3
rep(x = 1:3, each = 3)
## [1] 1 1 1 2 2 2 3 3 3
#grepl

instead of setwd() he suggests going file > new project > new directory etc. The base directory is then where the project file is based. Then you can load up the data better because it makes the base directory relative

Did u know you can put a vector in as a variable in a function lmao

test datasets can be found by going data() and then selecting one of the datasets and putting that in the parentheses

data()
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
#help(trees)

plot(Height~Volume, data = trees)

#the ~ means 'as a function of'

Some dplyr learning (…PLIERS) select() does columns filter() does rows

#install.packages("dplyr")
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
some_trees_data <- select(trees, -Girth)# gets all the trees dataset except girth 
some_trees_data
##    Height Volume
## 1      70   10.3
## 2      65   10.3
## 3      63   10.2
## 4      72   16.4
## 5      81   18.8
## 6      83   19.7
## 7      66   15.6
## 8      75   18.2
## 9      80   22.6
## 10     75   19.9
## 11     79   24.2
## 12     76   21.0
## 13     76   21.4
## 14     69   21.3
## 15     75   19.1
## 16     74   22.2
## 17     85   33.8
## 18     86   27.4
## 19     71   25.7
## 20     64   24.9
## 21     78   34.5
## 22     80   31.7
## 23     74   36.3
## 24     72   38.3
## 25     77   42.6
## 26     81   55.4
## 27     82   55.7
## 28     80   58.3
## 29     80   51.5
## 30     80   51.0
## 31     87   77.0
# or take a look at just "girth" but also rename it since its its actually DBH 

select(trees, DBH = Girth)
##     DBH
## 1   8.3
## 2   8.6
## 3   8.8
## 4  10.5
## 5  10.7
## 6  10.8
## 7  11.0
## 8  11.0
## 9  11.1
## 10 11.2
## 11 11.3
## 12 11.4
## 13 11.4
## 14 11.7
## 15 12.0
## 16 12.9
## 17 12.9
## 18 13.3
## 19 13.7
## 20 13.8
## 21 14.0
## 22 14.2
## 23 14.5
## 24 16.0
## 25 16.3
## 26 17.3
## 27 17.5
## 28 17.9
## 29 18.0
## 30 18.0
## 31 20.6
filter(some_trees_data, Height > 70 | Volume < 17) 
##    Height Volume
## 1      70   10.3
## 2      65   10.3
## 3      63   10.2
## 4      72   16.4
## 5      81   18.8
## 6      83   19.7
## 7      66   15.6
## 8      75   18.2
## 9      80   22.6
## 10     75   19.9
## 11     79   24.2
## 12     76   21.0
## 13     76   21.4
## 14     75   19.1
## 15     74   22.2
## 16     85   33.8
## 17     86   27.4
## 18     71   25.7
## 19     78   34.5
## 20     80   31.7
## 21     74   36.3
## 22     72   38.3
## 23     77   42.6
## 24     81   55.4
## 25     82   55.7
## 26     80   58.3
## 27     80   51.5
## 28     80   51.0
## 29     87   77.0
# the vertical line means OR like atleast one of them is true 

filter(some_trees_data, Height > 70 & Volume < 17) 
##   Height Volume
## 1     72   16.4
# this one requires both to be true 

some_trees_data <-mutate(some_trees_data, height_m = round(Height * 0.3048, 2))

summarize(some_trees_data,
          mean_height = mean(height_m),
          max_vol = max(Volume))
##   mean_height max_vol
## 1    23.16452      77
#group_by - use within summarize to give summaries by a group

Session info

sessionInfo()
## R version 4.4.2 (2024-10-31 ucrt)
## Platform: x86_64-w64-mingw32/x64
## Running under: Windows 10 x64 (build 19045)
## 
## Matrix products: default
## 
## 
## locale:
## [1] LC_COLLATE=English_Canada.utf8  LC_CTYPE=English_Canada.utf8   
## [3] LC_MONETARY=English_Canada.utf8 LC_NUMERIC=C                   
## [5] LC_TIME=English_Canada.utf8    
## 
## time zone: America/Edmonton
## tzcode source: internal
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] dplyr_1.1.4
## 
## loaded via a namespace (and not attached):
##  [1] digest_0.6.37     R6_2.6.0          fastmap_1.2.0     tidyselect_1.2.1 
##  [5] xfun_0.50         magrittr_2.0.3    glue_1.8.0        cachem_1.1.0     
##  [9] tibble_3.2.1      knitr_1.49        pkgconfig_2.0.3   htmltools_0.5.8.1
## [13] generics_0.1.3    rmarkdown_2.29    lifecycle_1.0.4   cli_3.6.3        
## [17] vctrs_0.6.5       sass_0.4.9        withr_3.0.2       jquerylib_0.1.4  
## [21] compiler_4.4.2    rstudioapi_0.17.1 tools_4.4.2       pillar_1.10.1    
## [25] evaluate_1.0.3    bslib_0.9.0       yaml_2.3.10       rlang_1.1.5      
## [29] jsonlite_1.8.9