R Programming Fundamentals

Seq Function

seq(from = 1, to = 1, by = ((to - from) / (length.out - 1)), 


  • getwd() - returns working directory.
  • setwd(“E:\STA4502\RCode”) - set the working directory to “E:\STA4502\RCode.
  • cbind(x,y) - combine two vectors of same length (x,y) to make a matrix
Our vector will automatically convert our data type if we bind vectors of different data types into a matrix or vector.
  • data.frame(x,y) - combine two vectors of different types into a dataframe while preserving the original variables’ datatypes. Dataframes can handle different length vectors.
  • M = matrix(1:20, nrow = 4, ncol = 5)
  • W = list(Matrix, charVector, intVector) - lists can handle basically all types of parameters.


Ctrl + L

  • clears the R console
    • this does not remove the variables from memory.
  • rm(list=ls()) - this will erase the memory.

Var Types

  1. character
  2. numeric (real numbers)
  3. integer
  4. complex
  5. logical (True/False)


Vectors are the most basic R object. An empty vector may be created with vector().

Vectors may only contain objects of the same class.

Lists, while represented as a vector, can break the rule above and contain objects of different classes.

The c() function can be used to create vectors by concatenating things together.

X = c(2.5, -3.5)

Dataframes, Matrices, and Lists

Data frames are standard data objects and are used to combine several variables of the same length and of potentially differing types into a single unit.

D = data.frame(x,y) 
# x   y 
# 11  1
# 218 1
# 123 1
# 36  1
# 10  1


Commenting is done like python, with #.

# This is a comment. 

Install Packages


Call Data

To see the collection of all datasets in a package.

data(package = "isdals")

library() function

library() invisibly returns the list of attached packages.



help() function

help() returns a short description of what is included within the data.



R Programming Fundamentals