An R function like "order" from Stata

The "splitstackshape" package for R

A while ago, a friend of ours presented me with a data problem. Her questionnaire had some questions where the respondent could provide multiple responses. You know, the "Check as many as apply" type of questions. One way that this data is commonly stored is to put a comma separated value into a single cell in a spreadsheet. In fact, if you use something like Google Forms to collect your data and have questions that use check-boxes, that's how your data will finally be stored in a Google Spreadsheet.

What exactly is "elegant" code in R?

In celebration of my achieving 10,000 “reputation” on Stack Overflow, I’m re-posting one of my questions from there that was (as I had expected) deleted after being live for about 5 hours. In that time, I never really got a satisfactory answer, so if anyone wants to offer one in the comments, that would be great!

I'm not at all religious, but...

… here is a goddess that I am happy to worship…

On the trucks around town ...

Anyone who has spent some time in India is sure to have noticed the slogans painted on the back of trucks, autos, and other vehicles advising “we two, ours one”. This is part of India’s “family planning” efforts–efforts which have had a pretty bumpy history that included a forced sterilization program. Originally, the slogans were “we two, ours two”, or at least that was the catchy English version–regional languages usually had a slogan more along the lines of “one family, two children”.

Stratified random sampling in R from a data frame

Important update The original function that was present at this post has been deleted. Instead, I’ve posted a much improved version for the sake of others visiting this page. The function is presently defined as: Arguments df: The input data.frame group: The grouping column(s). Can be a character vector or the numeric positions of the columns. size: The desired sample size. Can be a decimal (proportionate by group) or an integer (same number of samples per group).

Reshaping data in R revisited

A year ago, I wrote a post about reshaping data from a wide format to a long format. I thought that considering how much time had passed, it would be good to revisit R’s in-built reshape functions. For these examples, I’ve copied the Stata examples from the UCLA Academic Technology Services’s “Reshape data wide to long” page. Since the data is provided in Stata dta files, you need to first load the “foreign” package to be able to read the data in R.

The Cover Chain...

I was flipping through some of the old books that I used to scribble in way back when, and I came across a page that had the following:

This was a little idea that I had long before So, sue me already, back when I loved making mix-tapes for my friends. This mix-tape never materialized, and since then, my music exposure has increased quite a bit, leading to what I think is a pretty damn impressive compilation….

Read on… download… enjoy!

Regular expressions in R

In my last post, I showed a few things I had figured out recently related to regular expressions. By now, you have also figured out that I like figuring things out in R, and application of regular expressions is one of these things.

Sounds interesting. Is that a regular expression?

I’ve been meaning to learn how to use regular expressions for quite some time now, but just never seemed to get around to doing so. The other night, I decided to take a stab at them though, and over the past few days, I’ve sort of managed to learn a few tricks. Some of these might seem unnecessary, particularly since the examples comprise relatively small chunks of text. But, hopefully you can also see the application of the same techniques for larger text files. In some of the examples, I’ve also included how it might help with preparing your data for use with a program like R. For all of these examples, I’ve used Geany as my text editor. I suggest you use a good text editor like Geany or Notepad-plus-plus too.