R cheat sheet

May 30, 2011 at 8:05 pm Leave a comment

People who write cheat sheets don’t seem to understand the value of plain text. If you like pdfs you might prefer this:

http://cran.r-project.org/doc/contrib/Short-refcard.pdf

Warning! These are notes to myself made when not trying particularly hard to understand the syntax of R, they may not be optimal

apropos, help, etc

Add a column to a data frame f taking a constant value (think outer join):
merge(frame, data.frame(b=c(1)))

Stack two data frames
rbind(frame1, frame2)

Import:
source(‘x’)

Run R in batch mode
R < fit.r –no-save

Read csv or similar
read.table(file=’name’)

Linear model fitting: # linear model
lm(a ~ b + c)
lm(column1 ~ column2, frame)

names(frame) – List column names

TRUE, FALSE

??

R versus python.

Higher level (more domain specific), a more ugly programming language. Kitchen sink more immediately accessible but less well packed.
Classic DSL versus general purpose language. Key point: R has a vast kitchen sink .

— Sequences

1:10 = 1,2,3,…10
seq(0, 1, 0.2) = [0, 0.2, … 1.0]

— Postgres —

RPostgreSQL.

library(RPostgreSQL)
conn = dbConnect(PostgreSQL(), user=”user”, dbname=”db”, host=”localhost”, port=”port”)
results <- dbGetQuery(conn, query)
# beautiful results

— Functional programming

Map
Filter
Reduce

— Plotting

R plots into a device. A device can be a file or a window

dev.new() – Create a new window
dev.list() – List windows
dev.set(number) – Set the window
plot() – Plot some stuff (clear previous plot)
points – add points to an existing plot.

The plot function in R is a magic do what I mean function. It will
* Plot all 2-d projections if given a data frame
* Plot objects that you build (like clusters)

— Package management

install.packages(‘Hmisc’)

— Old values

.Last.value — last value (_) in python

— Matrix

t – Transpose

Advertisements

Entry filed under: Uncategorized. Tags: .

Rule-based automation of gnucash transaction source detection Tasker recording weight for android

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


May 2011
M T W T F S S
« Apr   Jun »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

%d bloggers like this: