Eval in R: Running Code From a String

It’s (very) occasionally quite useful to be able to execute code from a string, similarly to eval in ruby or javascript. You might use this to, eg, read a directory full of csv files and turn each filename into a dataframe containing the corresponding csv. This is difficult to write without such run [...]


Column Names of R Data Frames

Say you read a data frame from a file but you don’t like the column names. Here’s how you go about labelling them as you like. Start with a simple csv file:

col1, col2, col3
“1,233″, “$12.79″, “$1,333,233.17″
“470″, “$1,113.22″, “$0.12″

Load it, and see what we get:

data data
col1 [...]


Cleaning Data in R: csv files

When you read csv files, you regularly encounter Excel encoded csv files which include extraneous characters such as commas, dollar signs, and quotes. Such a file might look like

col1, col2, col3
“1,233″, “$12.79″, “$1,333,233.17″
“470″, “$1,113.22″, “$0.12″

and call it dirty.csv.
Using read.csv will leave you with:

> data data
col1 [...]


Using R

I intend to talk about a bunch of things, mostly involving R, that I had to learn the hard way.  Hopefully this will not only serve as a set of notes for me but help someone else out along the way.
So, say you are running R in the interpreter on either Windows or Mac.  You [...]