1.1

Create two objects in your environment, x and y. Assign x as a vector of numbers 1, 2, and 3. Assign y as a vector of numbers 4, 5, and 6. Once complete, check that both objects are visible in your RStudio environment.

x <- c(1, 2, 3)
y <- c(4, 5, 6)
x
## [1] 1 2 3
y
## [1] 4 5 6

1.2

Clear your environment. Check that x and y are no longer in the environment by typing each letter in the console. What is the result?

rm(list = ls())

1.3

Check your R session info. Which version of R are you running? Which version of the knitr package are you running? Write these details below.

sessionInfo()
## R version 4.3.3 (2024-02-29)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 22.04.4 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## time zone: Etc/UTC
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## loaded via a namespace (and not attached):
##  [1] crayon_1.5.2     vctrs_0.6.5      knitr_1.45       cli_3.6.2       
##  [5] xfun_0.42        rlang_1.1.3      stringi_1.8.3    jsonlite_1.8.8  
##  [9] glue_1.7.0       bit_4.0.5        htmltools_0.5.7  sass_0.4.8      
## [13] hms_1.1.3        fansi_1.0.6      rmarkdown_2.26   jquerylib_0.1.4 
## [17] evaluate_0.23    tibble_3.2.1     fastmap_1.1.1    tzdb_0.4.0      
## [21] yaml_2.3.8       lifecycle_1.0.4  stringr_1.5.1    compiler_4.3.3  
## [25] getopt_1.20.4    pkgconfig_2.0.3  optparse_1.7.4   digest_0.6.35   
## [29] R6_2.5.1         readr_2.1.5      tidyselect_1.2.1 utf8_1.2.4      
## [33] vroom_1.6.5      pillar_1.9.0     parallel_4.3.3   magrittr_2.0.3  
## [37] bslib_0.6.1      tools_4.3.3      bit64_4.0.5      cachem_1.0.8

Practice on Your Own!

P.1

Create a vector z with the numbers 0 to 9. Set the seed for the R random number generator to 1234. Draw 5 numbers at random from z using sample(x = z, size = 5, replace = TRUE). If you repeat the seed code and sample code multiple times in the same chunk, what do you observe?

z <- 0:9
set.seed(1234)
sample(x = z, size = 5, replace = TRUE)
## [1] 9 5 4 8 4
set.seed(1234)
sample(x = z, size = 5, replace = TRUE)
## [1] 9 5 4 8 4
set.seed(1234)
sample(x = z, size = 5, replace = TRUE)
## [1] 9 5 4 8 4

P.2

Run the sample(x = z, size = 5, replace = TRUE) statement again, but this time without running the set.seed() line. What do you notice about the 5 numbers?

sample(x = z, size = 5, replace = TRUE)
## [1] 5 3 1 6 5