knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Rdlazer




RStudio Basics

\newline

\newline




Console Basics

?Rdlazer
help(Rdlazer)
help("Rdlazer")




Comments




Basic Programming From An R Perspective


character strings


Boolean logic
*named after British mathematician George Bool; it is said he died because he was set to FALSE*


simple maths


variables


functions

\newline

Use the foo function to play around with function calls.


flow control

several special constructs allow for controlling code behavior

1. perform actions conditionally with if and else:

if (condition) {
  expression
}

\newline

if (condition) {
  expression1
} else {
  expression2
}

\newline

if (condition1) {
  if (condition2) {
    expression1
  } else {
    expression2
  } else {
    expression3
  }
}

\newline

if (condition1) {
  exrpession1
} else if (condition2) {
  exrpession2
} else if (condition3) {
  exrpession3
} else {
  exrpession4
}

\newline

2. perform actions iteratively with loops:

\newline

for (iterator in sequence) {
  expression1
  expression2
  expression...
  }

\newline

repeat {
  expression1
  expression2
  expression...
}

\newline

while(condition) {
  expression1
  expression2
  expression...
}




A Look Ahead

The following material will be covered in detail in following lectures. This is just a sneak peak that will be necessary to solve the homework assignments.

1) vectors - the basic data structure in R is called a vector - it is a sequence of items of the same type; thus a vector also has a type - the number of items in a vector constitutes its length - vectors are most commonly created with the function c

# build a character vector
c('one', 'two', 'three', 'four')

2) sets - a vector can be thought of as a set of elements - you can test whether something is an element of a vector with function is.element or %in%

3) concatenating strings - character strings can be concatenated with the function paste




olobiolo/Rdlazer documentation built on Aug. 6, 2022, 11:37 a.m.