Skip to main content

Posts

Showing posts from February, 2013

FillIn: a function for filling in missing data in one data frame with info from another

Update (10 March 2013):FillIn is now part of the budding DataCombine package.Sometimes I want to use R to fill in values that are missing in one data frame with values from another. For example, I have data from the World Bank on government deficits. However, there are some country-years with missing data. I gathered data from Eurostat on deficits and want to use this data to fill in some of the values that are missing from my World Bank data.Doing this is kind of a pain so I created a function that would do it for me. It's called FillIn.An Example Here is an example using some fake data. (This example and part of the function was inspired by a Stack Exchange conversation between JD Long and Josh O'Brien.)First let's make two data frames: one with missing values in a variable called fNA. And a data frame with a more complete variable called fFull.# Create data set with missing values naDF <- data.frame(a = sample(c(1,2), 100, rep=TRUE), b = sample(c(…

InstallOldPackages: a repmis command for installing old R package versions

A big problem in reproducible research is that software changes. The code you used to do a piece of research may depend on a specific version of software that has since been changed. This is an annoying problem in R because install.packages only installs the most recent version of a package. It can be tedious to collect the old versions.On Toby Dylan Hocking's suggestion, I added tools to the repmis package so that you can install, load, and cite specific R package versions. It should work for any package version that is stored on the CRAN archive (http://cran.r-project.org).To only install old package versions use the new repmis command InstallOldPackages. For example:# Install old versions of the e1071 and gtools packages. # Create vectors of the package names and versions to install # Note the names and version numbers must be in the same order Names &lt- c("e1071", "gtools") Vers &lt- c("1.6", "2.6.1") # Install old package ver…