Statistics and Statistical Programming (Winter 2017)/R lecture outline: Week 1: Difference between revisions

From CommunityData
(Created page with "== Lecture Outline == * using R as a calculator: ** addition: 2 + 2 ** subtraction: 2 - 3 ** multiplication: 5 * 4 ** division: 5/2 ** more complicated stuff: use parentheses...")
 
Line 24: Line 24:
*** log1p() — super useful!
*** log1p() — super useful!
*** check your reference card for many, many more
*** check your reference card for many, many more
* vectors: you can think of a vector as like a list of things that are all the same time (lists, which will come to letter, actually refer to lists of things that might be of different types!)
** in R, all variables are vectors! although many have just one thing in them! that's why it prints out [1] next to every numbers

Revision as of 21:07, 3 January 2017

Lecture Outline

  • using R as a calculator:
    • addition: 2 + 2
    • subtraction: 2 - 3
    • multiplication: 5 * 4
    • division: 5/2
    • more complicated stuff: use parentheses!
    • powers: 2^2; 2^3
  • variables
    • the basic concept and how they work
    • syntax for assignment: use <- (although = equals too, it's not idiomatic R)
    • what makes a valid variables name: starts with a letter, contains letters and numbers; case is important; instead of spaces, use "." (not _ as in Python, although _ will usually work too)
    • saving numbers to variables: cups.of.flour <- 2
    • special variables built in: pi (we'll see many more)
  • types of variables
    • numeric: we've already seen, with or without the decimal point
    • character: name <- "mako" (uses single or double quotes)
    • logical: TRUE or FALSE (all caps)
  • functions: contains parens right after the variable name
    • there are many built in functions including:
      • sqrt()
      • log()
      • log1p() — super useful!
      • check your reference card for many, many more
  • vectors: you can think of a vector as like a list of things that are all the same time (lists, which will come to letter, actually refer to lists of things that might be of different types!)
    • in R, all variables are vectors! although many have just one thing in them! that's why it prints out [1] next to every numbers