Selected functions I've written for use with R
R Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Selected functions I've written for use with R. Full documentation available in the "docs" folder (or as a PDF).

All functions can be downloaded from the "scripts" folder.

Alternatively, if you have the "RCurl" package installed, you can use:

baseURL = c("")
source(textConnection(getURL(paste0(baseURL, "scripts/---script-name---.R"))))

All scripts mentioned in the snippets section are found in a single snippets.R script.

Functions include:

  1. concat.split.R

    Use to split cells which contain concatenated data into separate columns. Works with string and numeric data. For numeric data, the splitted output can retain original values or be recoded as "1" and "NA" to facilitate frequency calculations. Can also split data into a list within a data.frame.

  2. df.sorter.R

    Sort a data.frame by rows, columns, or both. Can also be used to subset data.

  3. multi.freq.table.R

    Takes columns from a data.frame containing Boolean multiple-response data and tabulates the output.

  4. RandomNames.R

    Uses data from the Genealogy Data: Frequently Occurring Surnames from Census 1990--Names Files web page to generate a data.frame with random names.

  5. row.extractor.R

    Use to extract rows which contan a specified column's min, median, or max values, or to extract rows with specified quantiles.

  6. sample.size.R

    Used to determine the desired sample size of a given population, or the confidence interval for a given population and sample.

  7. stratified.R

    Used to sample from a data.frame according to a grouping (or stratification) variable.

  8. stringseed.sampling.R

    The stringseed.sampling() function is designed as a batch sampling function that allows the user to specify any alphanumeric input as the seed per sample in the batch.

  9. table2df.R

    The table2df() function takes an object of class table, ftable, or xtabs and converts it to a data.frame or a list of data.frames.


The snippets.R script includes several small "utility" functions. In cases where they are functions I've found online, I've mentioned the source in the head of the function.

Snippets include:


    Loads all scripts and data files from a specified set of directories matching a specified pattern.

  2. unlist.dfs

    Takes a list of data.frames and assigns them as individual data.frames in the current workspace.

  3. dfcols.list

    Takes a data.frame and converts it to a list where each list item represents one of the columns from the original data.frame.

  4. mv

    Renames objects in the workspace in one step, instead of having to copy the object and remove the original object.

  5. tidyHTML

    Reformats a web page using HTML Tidy (the online service) and uses the XML package to parse the resulting file. Can optionally save the reformatted page.

  6. round2

    Rounds numbers according to the rule you might have learned in school, not according to "round to even" (which is less biased and is used by R).

  7. CBIND

    Binds (by columns) data.frames with differing number of rows, filling the extra rows with NA values.

  8. randomNamesOnline

    Like the RandomNames() function, but uses an online service ( to generate the names.

  9. stringseed.basic

    Like the stringseed.sampling() function, but uses a much more basic approach to generating the seed. Also known as TDASample.R.