Notes on R

Back To Mike's WebToys Page!

Sadly, my (increasinly extensive) notes were lost in a file-copying mishap.  Let this be a lesson to everyone else: back up your work!! :)

For examples, stuff you're supposed to type in is listed like this; output from R is listed like this.

Misc. Notes

i.i.d
Independent and identically distributed.
Wikipedia definition

Basic Data Types: Data Frames

data.frame()
TODO
as.data.frame()
TODO

Basic Data Types: List Ops

 c( values....) - combine
Puts all the arguments into a single vector
stack( frame)
From the documentation: "Stacking vectors concatenates multiple vectors into a single vector along with a factor indicating where each observation originated. Unstacking reverses this operation."
Example:
list1 = c( 1, 2, 3)
list2 = c( 3, 4, 5)
allLists = data.frame(list1, list2)
stack(allLists)
values ind
1 1 list1
2 2 list1
3 3 list1
4 3 list2
5 4 list2
6 5 list2

File-Related

getwd( ) / setwd( "path" )
Gets the current working directory, or sets it.
data( "filename" )
Reads data from a file, into memory.  From the docs:

Currently, four formats of data files are supported:

  1. files ending ‘.R’ or ‘.r’ are source()d in, with the R working directory changed temporarily to the directory containing the respective file. (data ensures that the utils package is attached, in case it had been run via utils::data.)
  2. files ending ‘.RData’ or ‘.rda’ are load()ed.
  3. files ending ‘.tab’, ‘.txt’ or ‘.TXT’ are read using read.table(..., header = TRUE), and hence result in a data frame.
  4. files ending ‘.csv’ or ‘.CSV’ are read using read.table(..., header = TRUE, sep = ";"), and also result in a data frame.

Graphics:

Boxplot( data )
Draws box-and-whisker a plot. If data is a list, draws a single plot. If data is a frame, draws one plot per data list the frame contains, side-by-side.

ANOVA:

oneway.test(values ~ ind, data=df,var.equal=T)

TODO
anova(lm(values ~ ind, data=df))
TODO
aov
Note that you'll need to use the summary command to get more info

 

Back To Mike's WebToys Page!