1 Set up

  1. Installed R, then R Studio. https://posit.co/download/rstudio-desktop/

  2. Reading up on the help files from official R website

    • the R manuals https://cran.r-project.org/doc/manuals/r-release/R-intro.html

    • there are many other websites that might be easier to read

    • The help() function and ? help operator in R provide access to the documentation pages for R functions, data sets, and other objects, both for packages in the standard R distribution and for contributed packages. To access documentation for the standard lm (linear model) function, for example, enter the command help(lm) or help("lm"), or ?lm or ?"lm" (i.e., the quotes are optional). ’summary(mtcars).

2 2 Coding Best Practices

http://adv-r.had.co.nz/Style.html

2.1 Notation and naming

  • file names should me meaningful + informative

  • variable and function names should be lowercase. Use underscore (‘_’) to separate words

2.2 Syntax

  • Place spaces around all infix operators (=+-<-, etc.).

2.3 Organisation - Commenting guidelines

  • Comment your code. Each line of a comment should begin with the comment symbol and a single space: #. Comments should explain the why, not the what.

2.4 Basic Data Types

2.5 What are R Data types?

R Data types are used to specify the kind of data that can be stored in a variable. 

For effective memory consumption and precise computation, the right data type must be selected. 

Each R data type has its own set of regulations and restrictions.

basic data types in R can be divided into the following types:

  • numeric - (10.5, 55, 778)

    • decimals
  • integer - (1L, 55L, 100L, where the letter “L declares this as an integer)

  • character - (a.k.a. string) - (“k”, “R is exciting”, FALSE”, “11.5”)

    • Addresses or names, states or countries
  • logical - (aka boo ean) - (TRUE or FALSE)

    • true is usually 1 and false is usually 0
  • complex - (9+3i, where i is the imaginary part)

    • popular in physics, but not in business/economics

2.6 Data Structures

?datasets()
df <- mtcars
df$mpg2 <- as.integer(df$mpg)
df$mpg3 <- as.numeric(df$mpg2)

  
df <- as.data.frame(Titanic)
2 > 3
## [1] FALSE

Let me begin by introducing basic math operations

3 Arithmetic Operations

3.1 Addition

2+2
## [1] 4

3.2 Subtraction

5 - 4
## [1] 1

3.3 Multiplication

5 * 5
## [1] 25

3.4 Division

10 / 2
## [1] 5

{knitr::opts_chunk$set(echo = TRUE)}