Articles by Tony Cookson

Using apply() to create a unique id

February 6, 2012 | Tony Cookson

Suppose you have a data set with two identifiers. For example, maybe you're studying the relationships among firms in an industry and you have a way to link the firms to one another. Each firm has an id, but the unique unit in your data set is a pair...
[Read more...]

Splitting Vectors of Uneven Strings

July 29, 2011 | Tony Cookson

Suppose you have a vector of names such that the first three words in the vector contain relevant information, but there is a bunch of extraneous stuff. For example,Our goal is to collapse the first three words into one contiguous string (without the ...
[Read more...]

An application of aggregate() and merge()

June 5, 2011 | Tony Cookson

Today, I encountered an interesting problem while processing a data set of mine. My data have observations on businesses that are repeated over time. My data set also contains information on longitude and latitude of the business location, but unfort...
[Read more...]

Recreational R: Simulating a Card Trick

May 30, 2011 | Tony Cookson

In this post, I simulate an interesting card trick, which was described by a friend of mine named Xan. Here's Xan's description of the card trick:I put a deck of cards down face up on the table. Meanwhile you think of a secret number between 1 and 1...
[Read more...]

An Application of boot() to IV regression

May 28, 2011 | Tony Cookson

Bootstrapping standard errors can be a useful technique when obtaining closed form for the standard error formula is difficult or intractable. In this post, I give an example of how to use R to create a bootstrap sampling distribution in the context o...
[Read more...]

Describing Data: Frequently Used Commands

May 13, 2011 | Tony Cookson

Obtaining a coherent numerical summary of data is a common task, and it is common to want to port these summary statistics into a table of results. When I am in interactive mode with my data, I use the summary() command applied to my data frame. For ...
[Read more...]

Forming Formulas

April 29, 2011 | Tony Cookson

One of the first functions a new R user learns how to use is the lm() command, which involves stating the model formula.lm(y~x1+x2, data=mydata)After a while, this just becomes a natural way to say "I want a regression of y on x1 and x2 ...
[Read more...]

Automatically Save Your Plots to a Folder

April 26, 2011 | Tony Cookson

Suppose you're working on a problem that involves a loop for calculations. At each iteration inside the loop, you want to construct a plot. Not only do you want to see the plot, but you would like to save each plot for a presentation, report or paper...
[Read more...]

R Bloggers

April 26, 2011 | Tony Cookson

I recently found a great resource for R in the blogosphere, the R Bloggers Blog Aggregator. Basically, the site aggregates posts from a bunch of blogs about R (like this one!) into a giant feed of uses for R. If you are interested in learning more ab...
[Read more...]

Merging Data Video Tutorial

April 25, 2011 | Tony Cookson

Here's a video tutorial where I walk through some code that does what the previous post describes.The FRED data is used extensively for macroeconomics. You might these data useful for joining in graph fights in the blogosphere.
[Read more...]

Dates in R and the First Day of the Month

April 23, 2011 | Tony Cookson

I spent some time this morning learning about how R thinks about dates in R. I found this website to be a useful guide.Imagine that your data are dates in a standard format [YEAR-MONTH-DAY (as in 2011-23-04) is one such format] and you want a vector o...
[Read more...]

Good Looking Maps in R

April 21, 2011 | Tony Cookson

I haven't yet tried this, but it looks like a nice package.In one recent project I needed to draw several maps and visualize different kinds of geographical data on it. I found the combination of R/ggplot/maps package extremely flexible and powerful,...
[Read more...]

Common Data Creation Commands

April 19, 2011 | Tony Cookson

Here is a video tutorial where I go through some of the most commonly used commands in creating and manipulating data. As soon as I want to do more than just running a single regression, I use these commands more than any other set of commands (in som...
[Read more...]
1 2

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)