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
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())
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.5.0 (2025-04-11)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.2 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.26.so; LAPACK version 3.12.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_2.1.0 ThemePark_0.0.1 naniar_1.1.0 lubridate_1.9.4
## [5] forcats_1.0.0 stringr_1.5.1 dplyr_1.1.4 purrr_1.0.4
## [9] readr_2.1.5 tidyr_1.3.1 tibble_3.2.1 ggplot2_3.5.2
## [13] tidyverse_2.0.0
##
## loaded via a namespace (and not attached):
## [1] writexl_1.5.4 tidyselect_1.2.1 farver_2.1.2
## [4] fastmap_1.2.0 promises_1.3.2 digest_0.6.37
## [7] timechange_0.3.0 toastui_0.4.0 mime_0.13
## [10] lifecycle_1.0.4 magrittr_2.0.3 compiler_4.5.0
## [13] rlang_1.1.6 sass_0.4.10 tools_4.5.0
## [16] utf8_1.2.4 yaml_2.3.10 data.table_1.17.0
## [19] knitr_1.50 labeling_0.4.3 htmlwidgets_1.6.4
## [22] bit_4.6.0 classInt_0.4-11 curl_6.2.2
## [25] shinybusy_0.3.3 showtextdb_3.0 RColorBrewer_1.1-3
## [28] KernSmooth_2.23-26 withr_3.0.2 shinyWidgets_0.9.0
## [31] grid_4.5.0 sysfonts_0.8.9 xtable_1.8-4
## [34] e1071_1.7-16 scales_1.4.0 optparse_1.7.5
## [37] cli_3.6.5 rmarkdown_2.29 crayon_1.5.3
## [40] ragg_1.4.0 datamods_1.5.3 generics_0.1.3
## [43] rstudioapi_0.17.1 tzdb_0.5.0 readxl_1.4.5
## [46] getopt_1.20.4 cachem_1.1.0 proxy_0.4-27
## [49] parallel_4.5.0 cellranger_1.1.0 vctrs_0.6.5
## [52] jsonlite_2.0.0 hms_1.1.3 bit64_4.6.0-1
## [55] visdat_0.6.0 systemfonts_1.2.2 jquerylib_0.1.4
## [58] rio_1.2.3 glue_1.8.0 stringi_1.8.7
## [61] gtable_0.3.6 later_1.4.2 pillar_1.10.2
## [64] htmltools_0.5.8.1 showtext_0.9-7 reactable_0.4.4
## [67] R6_2.6.1 textshaping_1.0.0 vroom_1.6.5
## [70] evaluate_1.0.3 shiny_1.10.0 httpuv_1.6.15
## [73] bslib_0.9.0 phosphoricons_0.2.1 class_7.3-23
## [76] Rcpp_1.0.14 zip_2.3.2 xfun_0.52
## [79] pkgconfig_2.0.3
knitr
version: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
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