Blog Archives

Extracting Information From Objects Using Names()

March 17, 2013
By
Extracting Information From Objects Using Names()

One of the big differences between a language like Stata compared to R is the ability in R to handle many different types of objects at once, and combine them together or pull them apart.  I had a post about objects last year, but I thought I'd sh...

Read more »

Normal distribution functions

February 25, 2013
By
Normal distribution functions

Ah, the Central Limit Theorem.  The basis of much of statistical inference and how we get those 95% confidence intervals.  It's just so beautiful!  Lately, I have found myself looking up the normal distribution functions in R.  They...

Read more »

Converting a dataset from wide to long

February 1, 2013
By
Converting a dataset from wide to long

I recently had to convert a dataset that I was working with from a wide format to a long format for my analysis.  I struggled with this a bit, but finally found the right sources and the right package to do it, so I thought I'd share my practical ...

Read more »

Translating Weird R Errors

January 20, 2013
By
Translating Weird R Errors

I love R. I think it's intuitive and clever and overall a great language. But I do get really annoyed sometimes at the completely ridiculous, cryptic error messages it often gives me.  This post will go over some of those seemingly nonsensical err...

Read more »

For loops (and how to avoid them)

January 14, 2013
By
For loops (and how to avoid them)

My experience when starting out in R was trying to clean and recode data using for() loops, usually with a few if() statements in the loop as well, and finding the whole thing complicated and frustrating.In this post, I'll go over how you can avoi...

Read more »

Basics of Histograms

December 22, 2012
By
Basics of Histograms

Histograms are used very often in public health to show the distributions of your independent and dependent variables.  Although the basic command for histograms (hist()) in R is simple, getting your histogram to look exactly like you want takes g...

Read more »

Data types part 4: Logical class

November 30, 2012
By
Data types part 4: Logical class

First, an update:  A commentator has asked me to post my code so that it is easier to practice the examples I show here.  It will take me a little bit of time to get all of my code for past posts well-documented and readable, but I have uploa...

Read more »

Data types, part 3: Factors!

November 21, 2012
By
Data types, part 3: Factors!

In this third part of the data types series, I'll go an important class that I skipped over so far: factors.Factors are categorical variables that are super useful in summary statistics, plots, and regressions. They basically act like dummy variables t...

Read more »

Data types part 2: Using classes to your advantage

November 8, 2012
By
Data types part 2: Using classes to your advantage

Last week I talked about objects including scalars, vectors, matrices, dataframes, and lists.  This post will show you how to use the objects (and their corresponding classes) you create in R to your advantage.First off, it's important to remember...

Read more »

Data types, part 1: Ways to store variables

November 1, 2012
By
Data types, part 1: Ways to store variables

I've been alluding to different R data types, or classes, in various posts, so I want to go over them in more detail. This is part 1 of a 3 part series on data types. In this post, I'll describe and give a general overview of useful data types.  I...

Read more »