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     
## 
## other attached packages:
##  [1] esquisse_1.2.0  ThemePark_0.0.1 naniar_1.1.0    broom_1.0.5    
##  [5] jhur_0.2.1      lubridate_1.9.3 forcats_1.0.0   stringr_1.5.1  
##  [9] dplyr_1.1.4     purrr_1.0.2     tidyr_1.3.1     tibble_3.2.1   
## [13] ggplot2_3.5.0   tidyverse_2.0.0 readr_2.1.5    
## 
## loaded via a namespace (and not attached):
##  [1] writexl_1.5.0       tidyselect_1.2.1    farver_2.1.1       
##  [4] fastmap_1.1.1       promises_1.2.1      digest_0.6.35      
##  [7] timechange_0.3.0    mime_0.12           lifecycle_1.0.4    
## [10] ellipsis_0.3.2      magrittr_2.0.3      compiler_4.3.3     
## [13] rlang_1.1.3         sass_0.4.8          tools_4.3.3        
## [16] utf8_1.2.4          yaml_2.3.8          data.table_1.15.2  
## [19] knitr_1.45          labeling_0.4.3      htmlwidgets_1.6.4  
## [22] bit_4.0.5           curl_5.2.1          shinybusy_0.3.3    
## [25] showtextdb_3.0      withr_3.0.0         shinyWidgets_0.8.2 
## [28] grid_4.3.3          fansi_1.0.6         sysfonts_0.8.9     
## [31] xtable_1.8-4        colorspace_2.1-0    scales_1.3.0       
## [34] optparse_1.7.4      cli_3.6.2           rmarkdown_2.26     
## [37] crayon_1.5.2        ragg_1.3.0          datamods_1.4.5     
## [40] generics_0.1.3      rstudioapi_0.15.0   tzdb_0.4.0         
## [43] readxl_1.4.3        getopt_1.20.4       cachem_1.0.8       
## [46] parallel_4.3.3      cellranger_1.1.0    vctrs_0.6.5        
## [49] jsonlite_1.8.8      hms_1.1.3           bit64_4.0.5        
## [52] visdat_0.6.0        systemfonts_1.0.6   jquerylib_0.1.4    
## [55] rio_1.0.1           glue_1.7.0          stringi_1.8.3      
## [58] gtable_0.3.4        later_1.3.2         munsell_0.5.0      
## [61] pillar_1.9.0        htmltools_0.5.7     showtext_0.9-7     
## [64] reactable_0.4.4     R6_2.5.1            textshaping_0.3.7  
## [67] vroom_1.6.5         evaluate_0.23       shiny_1.8.0        
## [70] highr_0.10          backports_1.4.1     httpuv_1.6.14      
## [73] bslib_0.6.1         phosphoricons_0.2.0 Rcpp_1.0.12        
## [76] xfun_0.42           pkgconfig_2.0.3

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 the sample() function with replace = TRUE. Repeatedly run the code 3 times and note what you observe.

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

P.2

Run the sample() 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