Incredibly useful [R] functions and packages

caveat: this is NOT a complete list of functions (by any means), instead it is a list of functions I use on a regular basis that generally make my life easier

GENERAL ONE-LINE USEFULNESS

( ) – place parentheses around completed functions to get them to print the results directly into your [R] window

debug( ) – allows you to see the internal structure of functions so that you can tell where potential errors might be occurring

builtins( ) – list all built-in functions

append( ) – add elements to a vector

cbind( ) – combine by columns or rows a sequence of vector, matrix or data frames arguments

length( ) – return number of elements in vector x

dim( ) – return dimensions of an object

ls( ) – list objects in current working environment

unique(x) – remove duplicate entries in a vector

Sys.time( ); Sys.date( ) – return system time and date, respectively

getwd( ); setwd( ) – get and set working directory, respectively

list.files( ) – list files in a given directory*

file.info( ) – get information about specific files*

rm(list = setdiff(ls(), lsf.str())) – when you want to clear your variables from [R]’s memory but not your functions

*these functions can be executed with menu options in R-Studio and other R IDEs.

 

FOR THE LOVE OF GRAPHICS

par( ) – set or query graphical parameters, probably my favourite

points(x,y)  – add a set of points to an existing graph

abline( ) – adds a straight line to an existing graph, where specified

hist(x) – plot a histogram of x

pdf(); png( ); jpeg( ) – plot to pdf file, PNG file, or JPEG file, repsectively

image( ) – plot an image

 

PACKAGES

readxl – for reading in .xls and .xlsx files into [R] seamlessly

dplyr – for easy data manipulation

 

RSTUDIO TIPS

To create foldable code chunks or sections of text, 3 heading types can be created in RStudio. Note they all require that the non-executable heading line ends with 4 or more characters:

  1. #Section One—————
  2. #Section Two=========
  3. #Section Three########

Comments are closed