Eval in R: Running Code From a String
Filed in R, June 30, 2009, 5:55 pmIt’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
Filed in Data Munging, R, June 29, 2009, 6:45 pmSay 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
Filed in Data Munging, R, , 5:37 pmWhen 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
Filed in R, , 1:19 amI 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 [...]