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 "
Alternatively, if you have the "RCurl" package installed, you can use:
library(RCurl) baseURL = c("https://raw.github.com/mrdwab/2657-R-Functions/master/") source(textConnection(getURL(paste0(baseURL, "scripts/---script-name---.R"))))
All scripts mentioned in the
snippets section are found in a single
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
data.frameby rows, columns, or both. Can also be used to subset data.
Takes columns from a
data.framecontaining Boolean multiple-response data and tabulates the output.
Uses data from the Genealogy Data: Frequently Occurring Surnames from Census 1990--Names Files web page to generate a
data.framewith random names.
Use to extract rows which contan a specified column's
maxvalues, or to extract rows with specified quantiles.
Used to determine the desired sample size of a given population, or the confidence interval for a given population and sample.
Used to sample from a
data.frameaccording to a grouping (or stratification) variable.
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.
table2df()function takes an object of class
xtabsand converts it to a
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.
Loads all scripts and data files from a specified set of directories matching a specified pattern.
Takes a list of
data.frames and assigns them as individual
data.frames in the current workspace.
data.frameand converts it to a list where each list item represents one of the columns from the original
Renames objects in the workspace in one step, instead of having to copy the object and remove the original object.
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.
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).
Binds (by columns)
data.frames with differing number of rows, filling the extra rows with
RandomNames()function, but uses an online service (http://random-name-generator.info/) to generate the names.
stringseed.sampling()function, but uses a much more basic approach to generating the seed. Also known as