Skip to content

base

Reference of datar.base

See here for APIs ported from r-stats and here for APIs ported from r-utils

Legend:

Sample Status
normal API that is regularly ported
strike-through API that is not ported, or not an API originally
bold API that is unique in datar
italic Working in process

Constants

API Description Notebook example
pi the ratio of the circumference of a circle to its diameter.
letters the 26 lower-case letters of the Roman alphabet
LETTERS the 26 upper-case letters of the Roman alphabet
month.abb the three-letter abbreviations for the English month names
month.name the English names for the months of the year

Options

API Description Notebook example
options Allow the user to set and examine a variety of global options
get_option() Get the value of a certain option (R's getOption())
options_context() A context manager to temporarily modify the options

Arithmetic functions

API Description Notebook example
mean() Calculate the mean of the values
median() Calculate the median of the values
min() Calculate the min of the values
max() Calculate the max of the values
pmin() Calculate the min of the values rowwisely
pmax() Calculate the max of the values rowwisely
sum() Calculate the sum of the values
abs() Calculate the absolute values of the values
round() Round the numbers
var() Calculate the variance of the values
ceiling() Get the ceiling integers of the numbers
floor() Get the floor integers of the numbers
sqrt() Get the square root of the numbers
cov() Calculate the covariance of the values
prod() Calculate Product of the input
sign() Get the signs of the corresponding elements of x
signif() Rounds the values in its first argument to the specified number of significant digits
trunc() Get the integers truncated for each element in x
exp() Calculates the power of natural number
log() Computes logarithms, by default natural logarithm
log2() Computes logarithms with base 2
log10() Computes logarithms with base 10
log1p() Computes log(1+x)
quantile() Produces sample quantiles corresponding to the given probabilities.
sd(), std() Computes the standard deviation of the values
weighted_mean() Computes the weighted mean of the values
col_sums() Computes column sums of a dataframe
row_sums() Computes row sums of a dataframe
col_means() Computes column means of a dataframe
row_means() Computes row means of a dataframe
col_sds() Computes column sds of a dataframe
row_sds() Computes row sds of a dataframe
col_medians() Computes column medians of a dataframe
row_medians() Computes row medians of a dataframe

Bessel functions

API Description Notebook example
bessel_i() Bessel Functions of integer and fractional order of first kind
bessel_k() Bessel Functions of integer and fractional order of second kind
bessel_j() Modified Bessel functions of first kind
bessel_y() Modified Bessel functions of third kind

Casting values between types

API Description Notebook example
as_integer() as_int Cast data to integer
as_double() Cast data to double (numpy.float64)
as_float() Cast data to float (numpy.float_)
as_numeric() Cast data to numeric

Complex numbers

API Description Notebook example
re() Get the real part of a complex number
mod() Get the modulus of a complex number
im() Get the imaginary part of a complex number
arg() Get the argument of a complex number
conj() Get the complex conjugate of a complex number
is_complex() Test if data is complex number
as_complex() Cast data to a complex number

Cumulativate functions

API Description Notebook example
cumsum() Cummulative sum
cumprod() Cummulative product
cummin() Cummulative min
cummax() Cummulative max

Date functions

API Description Notebook example
as_date() Cast data to date
as_pd_date() Alias of pandas.to_datetime()

Factor data

API Description Notebook example
factor() Construct factor
droplevels() Drop unused levels
levels() Get levels of factors
is_factor() is_categorical Test if data is factor
as_factor() as_categorical Cast data to factor
is_ordered() Check if a factor is ordered
nlevels() Get number of levels of a factor
ordered() Create an ordered factor

Logical/Boolean values

API Description Notebook example
TRUE Logical true
FALSE Logical false
is_true() Test if data is scalar true (R's isTRUE)
is_false() Test if data is scalar false (R's FALSE)
is_logical() is_bool() Test if data is logical/boolean
as_logical() as_bool() Cast data to logical/boolean

NA (missing values)

API Description Notebook example
Inf Infinite number
NA Missing value
NaN Missing value, same as NA
is_na() Test if data is NA
any_na() Test if any element is NA
is_finite() Test if x is finite
is_infinite() Test if x is infinite
is_nan() Test if x is nan

NULL

API Description Notebook example
NULL NULL value
is_null() Test if data is null
as_null() Cast anything to NULL

Random

API Description Notebook example
set_seed() Set the randomization seed

Functions to create and manipulate sequences

API Description Notebook example
c() Collection of data
seq() Generate sequence
seq_len() Generate sequence with length
seq_along() Generate sequence along with another sequence
rev() Reverse a sequence
rep() Generate sequence with repeats
lengths() Get the length of elements in the sequence
unique() Get the unique elements
sample() Sample the elements from sequence
length() Get the length of data
match() match returns a vector of the positions of (first) matches of its first argument in its second.
rank() Returns the sample ranks of the values in a vector.
order() Returns a permutation which rearranges its first argument into ascending or descending order
sort() Sorting or Ordering Vectors

Special functions

API Description Notebook example
beta() Beta function
lbeta() Natural logarithm of beta function
gamma() Gamma function
lgamma() Natural logarithm of gamma function
digamma() the first derivatives of the logarithm of the gamma function.
trigamma() the second derivatives of the logarithm of the gamma function.
psigamma() polygamma funnction
choose() binomial coefficients
lchoose() the logarithms of binomial coefficients.
factorial() factorial
lfactorial() Natural logarithm of factorial

String functions

API Description Notebook example
is_character() is_str is_string Test if data is string
as_character() as_str as_string Cast data to string
grep() Test if pattern in string
grepl() Logical version of grep
sub() Replace substrings in strings
gsub() Replace all matched substring in strings
nchar() Get length of string
nzhcar() Test if string is not empty
paste() Concatenate strings
paste0() Concatenate strings with sep=''
sprintf() C-style string formatting
substr() Get substring
substring() Get substring with a start only
strsplit() Split strings with delimiter
startswith() Test if strings start with given prefix
endswith() Test if strings end with given suffix
strtoi() Convert strings to integers
chartr() Replace characters in strings
tolower() Transform strings to lower case
toupper() Transform strings to upper case
trimws() Remove leading and/or trailing whitespace from character strings.

Table

API Description Notebook example
table() Cross Tabulation and Table Creation
tabulate() Takes the integer-valued vector bin and counts the number of times each integer occurs in it.

Testing value types

API Description Notebook example
is_double() is_float() Test if data is double or float (numpy.float_)
is_integer() is_int() Test if data is integer
is_numeric() Test if data is numeric
is_atomic() Test is data is atomic
[is_element(),is_in()][96]|Test if value is an element of an array (R's%in`)

Trigonometric and hyper bolic functions

API Description Notebook example
cos() cosine
sin() sine
tan() tangent
acos() Arc-cosine
asin() Arc-sine
atan() Arc-tangent
atan2() atan(y/x)
cospi() cos(pi*x)
sinpi() sin(pi*x)
tanpi() tan(pi*x)
cosh() Hyperbolic cosine
sinh() Hyperbolic sine
tanh() Hyperbolic tangent
acosh() Hyperbolic cosine
asinh() Hyperbolic sine
atanh() Hyperbolic tangent

Which

API Description Notebook example
which() Which indices are True?
which_min() which_max() Where is the minimum or maximum or first TRUE or FALSE

Other functions

API Description Notebook example
glimpse() Get a glimpse of your data
cut() Convert Numeric to Factor
diff() Returns suitably lagged and iterated differences.
identity() Identity Function
expandgrid() Create a Data Frame from All Combinations of Factor Variables
outer() Compute the outer product of two vectors.
max_col() Find the maximum position for each row of a matrix
append() Add elements to a vector.
complete_cases() Get a bool array indicating whether the values of rows are complete in a data frame.
proportions(), prop_table Returns conditional proportions given margins
make_names() Make names available as columns and can be accessed by df.<name>
make_unique() Make the names unique, alias of make_names(names, unique=True)