Saturday, 20 April 2013

R: Basic Mathematical Functions

R can perform the usual mathematical operations, below are the functions:

Arithmetic
  • +    - addition
  • -    - subtraction
  • *    - multiplication
  • /    - division

Trigonometry
  • sin      - sine
  • cos      - cosine
  • tan      - tangent
  • asin    - sine inverse
  • acos    - cosine inverse
  • atan    - tangent inverse

Linear Algebra
  • +            - element-wise addition
  • -            - element-wise subtraction
  • *            - element-wise multiplication
  • /            - element-wise division
  • %*%        - matrix multiplication
  • t            - transpose
  • eigen    - eigenvalues and eigenvectors
  • solve    - inverse of matrix
  • ginv      - generalized inverse, requires MASS package
  • rbind    - combines vectors of observations horizontally into matrix class
  • cbind    - combines vectors of observations vertically into matrix class


Reference:
  1. Kabacoff, R. I. Matrix Algebra. Quick-R. Retrieved April 20, 2013.
  2. Trigonometric Functions. R Documentation. R.2.15.1

Monday, 1 April 2013

R: Installing, Loading, and Detaching Packages

To install a package in R, the function to be used is install.packages. Let say we want to install the ggplot2 package, simply code this with the following:

To install more than one package, utilize the concatenate function, c

Note that in executing the above codes, a dialogue box will pop up asking for the CRAN-Mirror, just choose the one that's in or near your country. Now to load these packages, run

And to detach these packages, run