DEV. Packaged version of CodeAndRoll. A collection of custom R functions. Works with MarkdownReports, SeuratUtils but also as a standalone set of more than 130 productivity tools.
Packaged version of the core functionalities (vector, matrix and list manipulations; math) of the formerly used CodeAndRoll (v1). A standalone set of more than >130 productivity functions. Used by MarkdownReports, ggExpress, SeuratUtils.
Install directly from GitHub via devtools with one R command:
# install.packages("devtools"); # If you don't have it.
require("devtools")
devtools::install_github(repo = "vertesy/CodeAndRoll2")
…then simply load the package:
require("CodeAndRoll2")
Alternatively, you simply source it from the web. This way function help will not work, and you will have no local copy of the code on your hard drive.
source("https://raw.githubusercontent.com/vertesy/CodeAndRoll2/master/CodeAndRoll2/R/CodeAndRoll2.R")
create a vector from a vector of names
create list from a vector with the names of the elements
Create a matrix from 2 vectors defining the row- and column names of the matrix. Default
Create a matrix from values in a vector repeated for each column / each row. Similar to
create an N-dimensional array from N vectors defining the row-,
A better version of is(). It can print the first “printme” elements.
A dim() function that can handle if you pass on a vector: then, it gives the length.
A dimnames() function that can handle if you pass on a vector: it gives back the names.
generate a table() with a fixed set of categories. It fills up the table with missing categories, that are relevant
grep returning the value
Show the most frequent elements of a table
Returns the position / index of the n highest values. For equal values, it maintains the original order
A combination of head() and tail() to see both ends.
Sort in decreasing order.
Alias for str_split_fixed in the stringr package
Find the n highest values in a named vector
Find the n lowest values in a named vector
Convert a dataframe column or row into a vector, keeping the corresponding dimension name.
Convert a dataframe column into a vector, keeping the corresponding dimension name.
Convert a dataframe row into a vector, keeping the corresponding dimension name.
…
Convert a vector with names into a tibble, keeping the names as rownames.
Converts any vector into a numeric vector, and puts the original character values into the names of the new vector, unless it already has
Converts any vector into a numeric vector, and puts the original character values into the names of the new vector, unless it already has
Converts your input vector into a character vector, and puts the original character values into the names of the new vector, unless it
linear transformation to a given range of values
Flip the values and the names of a vector with names
Sort a vector by the alphanumeric order of its names(instead of its values).
How many entries are duplicated
which values are duplicated?
which values are NA?
Fill up with a vector to a given length with NA-values at the end.
Signal clipping. Cut values above or below a threshold.
Signal clipping based on the input data’s distribution. It clips values
Converts your input vector into a logical vector, and puts the original character values into the names of the new vector, unless it
Convert a 2-column table(data frame) into a named vector. 1st column will be used as names.
Iterate over a vector by every N-th element.
mix entries so that they differ
numerate from x to y with additonal zeropadding
find second (third…) highest/lowest value in vector
Cumulative subtraction, opposite of cumsum()
Sum up vector elements with the same name
Return the names where the input vector is TRUE. The input vector is converted to logical.
Return the vector elements whose names are partially matched
Calls na.omit() and returns a clean vector
Omit infinite values from a vector.
Omit zero values from a vector.
Percentage of true values in a logical vector, parsed as
Percentage of a certain value within a vector or table.
Parse a sentence reporting the % of filter survival.
Remove values that fall outside the trailing N % of the distribution.
Replace every entry that is found in “replaceit”, by a single value provided by “to”
Awesome pattern matching for a set of values in another set of values. Returns a list with all kinds of
Calculates the median of each row of a numeric matrix / data frame.
Calculates the median of each column of a numeric matrix / data frame.
Calculates the median of each row of a numeric matrix / data frame.
Calculates the median of each column of a numeric matrix / data frame.
Calculates the CV of each ROW of a numeric matrix / data frame.
Calculates the CV of each column of a numeric matrix / data frame.
Calculates the CV of each ROW of a numeric matrix / data frame.
Calculates the CV of each column of a numeric matrix / data frame.
Calculates the minimum of each row of a numeric matrix / data frame.
Calculates the minimum of each column of a numeric matrix / data frame.
Calculates the maximum of each row of a numeric matrix / data frame.
Calculates the maximum of each column of a numeric matrix / data frame.
Calculates the SEM of each row of a numeric matrix / data frame.
Calculates the SEM of each column of a numeric matrix / data frame.
Calculates the SEM of each row of a numeric matrix / data frame.
Calculates the SEM of each column of a numeric matrix / data frame.
Calculates the SEM of each row of a numeric matrix / data frame.
Calculates the SEM of each column of a numeric matrix / data frame.
Calculates the SEM of each row of a numeric matrix / data frame.
Calculates the SEM of each column of a numeric matrix / data frame.
See more: https://stackoverflow.com/questions/20596433/how-to-divide-each-row-of-a-matrix-by-elements-of-a-vector-in-r
See more: https://stackoverflow.com/questions/20596433/how-to-divide-each-row-of-a-matrix-by-elements-of-a-vector-in-r
divide by row
Mutliply by row
Calculate Z-score over rows of data frame.
normalize each column to 1 million
normalize each column to the median of all the column-sums
normalize each column to the median of the columns
rotate a matrix 90 degrees.
Sort each column of a numeric matrix / data frame.
Sort a matrix. ALTERNATIVE: dd[with(dd, order(-z, b)), ]. Source: https://stackoverflow.com/
Create a copy of your matrix, where every entry is replaced by the corresponding row name. Useful if you want to color by row name in a
Create a copy of your matrix, where every entry is replaced by the corresponding column name. Useful if you want to color by column
trim whitespaces from the rownames
split a data frame by a factor corresponding to columns.
split a data frame by a factor corresponding to columns.
Subset rows and columns. It checks if the selected dimension names exist and reports if any of those they
Get the subset of rows with existing rownames, report how much it could not find.
Get the subset of cols with existing colnames, report how much it could not find.
Get odd or even columns or rows of a data frame
combine matrices by rownames intersect
Merge any data frames by rownames. Required plyr package
Merge 2 numeric data frames by rownames
cols have to be a vector of numbers corresponding to columns
cols have to be a vector of numbers corresponding to columns
Omit rows with NA values from a matrix. Rows with any, or full of NA-s
copy dimension and dimnames
lapply for multidimensional arrays
simplify 2D-list-array to a DF
multi dimensional lapply + arr.of.lists.2.df (simplify 2D-list-array to a DF)
Check if there are any duplocated rownames in a list of dataframes.
Intersect any number of lists.
Intersect any number of list elements. Faster than reduce.
lapply, then unlist
create a list with names from ALL variables you pass on to the function
Split a dataframe into a list by its columns. omit.empty for the listelments; na.omit
oSplit a dataframe into a list by its rows. omit.empty for the listelments; na.omit and
reorder elements of lists in your custom order of names / indices.
range of values in whole list
Combine 2 lists (of the same length) so that form every odd and every even element of a unified list. Useful for side-by-side comparisons,
convert a vector to a list with certain dimensions, taken from the list it wanna resemble
reverse list hierarchy
…
Convert a list to a full matrix. Designed for occurence counting, think tof table(). Rows = all ENTRIES
split a list by its names
split a list by its names
Combine 2 vectors (of the same length) so that form every odd and every even element of a unified vector.
Combine 2 data frames (of the same length) so that form every odd and every even element of a unified list. Useful for side-by-side
Convert a list to a vector repeating list-element names, while vector names are the list elements
Convert a list to a vector, with list elements names replicated as many times, as many elements each
Quasy symmetric difference of any number of vectors
…
Calculates the standard error of the mean (SEM) for a numeric vector (it
Calculates the fano factor on a numeric vector (it excludes NA-s
Calculates the geometric mean of a numeric vector (it excludes NA-s by default)
Calculates the mean of the log_k of a numeric vector (it excludes NA-s by default)
Calculates the moving / rolling average of a numeric vector.
Calculates the moving / rolling average of a numeric vector, using filter().
Calculates the moving / rolling standard error of the mean (SEM) on a numeric vector.
Calculates the moving / rolling standard error of the mean (SEM). It calculates it to the edge of the vector with incrementally smaller
Calculate shannon entropy