1  R

1.1 Why learn R?

  1. Statistical Analysis
    R provides powerful tools for conducting complex statistical analyses, which is essential for many scientific and social research disciplines.
  2. Data Visualization
    R excels in creating high-quality, publishable graphics, enabling clear communication of data insights.
  3. Data Manipulation
    It includes extensive libraries for handling and transforming data, making it easier to prepare large datasets for analysis.
  4. Open Source
    R is free to use, with a vast community that contributes packages and support, reducing software costs and increasing accessibility.
  5. Career Opportunities
    Proficiency in R is highly valued in many careers such as data science, economics, actuarial science and biostatistics, enhancing job prospects. Specifically, the SoA (Society of Actuaries) requires R as the main tool in their Advanced Topics in Predictive Analytics (ATPA) assessment.
  6. Ease of Learning
    While Python is often considered beginner-friendly, R has a significant advantage for data-related tasks once you master the basics. Designed specifically for data manipulation and analysis, learning core data science skills—data manipulation, visualization, and machine learning—can be more straightforward in R.

1.2 What is R and Rstudio?

R is a language and environment for statistical computing and graphics. It is a free, open-source program for which there are abundant online resources to support its use. R can be downloaded from http://cran.r-project.org.

RStudio is an integrated development environment (IDE) for R. It includes a console, syntax-highlighting editor that supports direct code execution, as well as tools for plotting, history, debugging and workspace management. RStudio can be downloaded from https://www.rstudio.com/products/rstudio/download/.

-
Figure 1.1: RStudio Interface

1.3 What is CRAN?

R is downloaded from the Comprehensive R Archive Network (CRAN). You will see later that we can also download packages from CRAN.

1.4 Exercise A

Q1

Let’s print Hello World in R.

Q2

Check what you can see when you type in Sys.time() in the R console.

Q3

Which is NOT an option for a file type when you go to File \(>\) New File in RStudio?

  • A. R script
  • B. Quarto Document
  • C. Shiny Web App
  • D. R Beamer Presentation
  • E. R Markdown