Personal R notes

Contents

[edit] 1 Basic meta-programming navigation

  • ls -- lists all available variables
  • attributes -- gets attributes of an object
  • dim -- gets the object dimensions
  • typeof -- tells you what type a variable is
  • names -- lists names, like in a list

[edit] 2 Deleting objects using grep on the names

rm(list=ls(pattern="PATTERN"))

Then run gc() afterwards to clear up all the delicious memory.

[edit] 3 Selecting things in one vector and not in another

v1[! v1 %in% v2]

[edit] 4 Find out the default parameters being graphed

Example:

par()$mar

[edit] 5 Find indices of max, etc in a matrix

m <- matrix(1:4,2,2); which(m == max(m),arr.ind=TRUE)
XHTML 1.1 CSS 2 Sec 508