Skip to content

Latest commit

 

History

History
81 lines (59 loc) · 2.33 KB

intro_notes.mdown

File metadata and controls

81 lines (59 loc) · 2.33 KB

Notes based on a reading of Emmanuel Paradis' R for Beginners

1.

Introduction

  • R is a language
  • Only objects in active memory are manipulated, not the data on the disk
  • Objects have attributes that specify what kind of data is represented
    • 2 intrinsic attributes of all objects
      • mode and length

Basic syntax

  • a function is always written with parentheses, even if the are empty; e.g.getwd()
    • A function without parentheses will display the content of the function
  • A value must be assigned to an object or it will not be stored in memory
  • ls() lists the objects in memory
  • Use the up arrow to scroll through previous commands
  • Regular sequences
    • The : operator
    • seq()
    • c()
    • rep()
    • factor() & levels()

Installation

RStudio

Packages and importing

Basic language commands

Getting help

  • The on-line help can be accessed from within R with the use of ?; e.g. ?lm
    • help(lm) and help('lm') are equivalent
    • These commands only search packages that are loaded in memory. To search all packages, set try.all.packages = TRUE
  • For a more detailed desciption of what the is contained in the help documentation, see page 7 of https://cran.r-project.org/doc/contrib/Paradis-rdebuts_en.pdf

Example of a typical workflow

Plug slack & blog

#2.

Reading in data

Working with data

  • Basic read in is read.table()
  • Saving data
    • write.table() or write() writes an objet in a file
    • Can record a group of objects by making them into a 'workspace' with save(x, y, z, file= "xyz.RData")

Making lists, data frames, converting between them

Indexing and selecting

Indexing

  • Single brackets
    • For example, to select the third value of vector x x[3]

Basics on objects

Types of data objects

  • Vector: one dimensional sequence of data elements
  • Matrix: a two-dimensional collection of data elements
    • e.g.
  • Data frame: A two-dimensional collection of data elements where vectors must be of the same length but may be of different class
  • List: A collection of data elements that may be of different classes and lengths

3.

Plotting

4.

Control flow

5.

Functions

6.

Document creation