This is a package of various functions that I've made which I've found useful while working on different projects. They fall into two categories:
library(rutilstb)
isid
FunctionThe isid
function can be used to detect whether or not a variable (or group of
variables) has unique values. It has three uses:
a <- 1:5 b <- c(1, 1, 2, 3, 4)
isid(a) isid(b)
users <- data.frame( user_id = 1:5, first_name = c('Tim', 'Brandon', 'Brandon', 'Arya', 'Cersei'), last_name = c('Book', 'Stark', 'Tully', 'Stark', 'Lannister') )
isid(users)
isid(users, keys = c('first_name', 'last_name'))
tabstat
FunctionThe tabstat
function can be used to view statistics based on categorical
variables within a data frame.
tabstat('mpg', mtcars, by = 'cyl') tabstat('mpg', mtcars, by = 'cyl', fns = list(median, IQR, length))
mdesc
FunctionThe mdesc
function gives a description of missing values in a data frame, and
where they are located.
df <- data.frame( a = 1:5, b = c(2, 3, NA, 4, 5), c = c(NA, 'x', 'y', 'z', NA) ) mdesc(df)
colMatcher
FunctionThe colMatcher
function tells the user if any two columns are identical.
df <- data.frame( x = 1:5, y = 101:105, z = 1:5, w = 101:105, v = letters[1:5] ) colMatcher(df) colMatcher(df, return_index = TRUE)
dfSplit
FunctionThe dfSplit
function splits a data.frame
into parts, either via a
training/test split, or a K-fold split.
df <- data.frame(matrix( rnorm(100 * 4), 100, 4 ))
split1 <- dfSplit(df, method = 'traintest', train_frac = 0.8) lapply(split1, dim) split2 <- dfSplit(df, method = 'traintest', train_n = 70) lapply(split2, dim) split3 <- dfSplit(df, method = 'kfold', K = 4) lapply(split3, dim)
fullRanker
FunctionThe fullRanker
function takes a matrix or data.frame
and successively
removes columns until it is of full rank.
X1 <- diag(4) X2 <- cbind(X1, 1)
fullRanker(X1) fullRanker(X2)
unpack
FunctionThe unpack
function simply takes objects in a list, and unpacks them into
the global (or otherwise unspecified) environment.
rm(list = ls()) ls() mylist <- list(a = 1:5, b = letters[1:6], c = rnorm(7)) unpack(mylist) ls()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.