Function reference
Strings
String manipulation functions.
| nchar | Return the number of characters in a string. Vectorised. |
| nzchar | Return True if string is non-empty. Vectorised. |
| paste | Concatenate vectors element-wise with sep, like R’s paste(). |
| paste0 | paste() with sep=’’. Equivalent to R’s paste0(). |
| grepl | Return True/False for each element of x matching pattern. Vectorised. |
| grep | Return indices (0-based) of elements in x matching pattern. |
| gsub | Replace all matches of pattern in x with replacement. Vectorised. |
| sub | Replace the first match of pattern in x with replacement. Vectorised. |
| trimws | Strip whitespace from strings. which: ‘both’, ‘left’, ‘right’. Vectorised. |
| toupper | Convert string to uppercase. Vectorised. |
| tolower | Convert string to lowercase. Vectorised. |
| startsWith | Return True if x starts with prefix. Vectorised. |
| endsWith | Return True if x ends with suffix. Vectorised. |
| strsplit | Split string x by split pattern. Returns list of lists. Vectorised. |
| substr | Extract substring from start to stop (0-based, inclusive). Vectorised. |
| chartr | Replace characters in old with corresponding characters in new. Vectorised. |
| formatC | Format numbers as strings. Vectorised. |
Vectors
Vector manipulation functions.
| which | Return 0-based indices where x is True, like R’s which() but Python-indexed. |
| which_min | Return 0-based index of the minimum value. |
| which_max | Return 0-based index of the maximum value. |
| diff | Return lagged differences of x. |
| cumsum | Cumulative sum. |
| cumprod | Cumulative product. |
| cummax | Cumulative maximum. |
| cummin | Cumulative minimum. |
| rev | Reverse a list. |
| duplicated | Return boolean list: True where element has appeared earlier. |
| setdiff | Elements in x not in y, preserving order. |
| intersect | Elements in both x and y, preserving order of x. |
| union | Unique elements from x and y combined, preserving order. |
| unique | Return unique elements preserving order. |
| seq_along | Return 0-based indices along x, like R’s seq_along() but Python-indexed. |
| seq_len | Return 0-based sequence of length n, like R’s seq_len() but Python-indexed. |
| seq | Generate a sequence, like R’s seq(), but 0-based by default. |
| r_range | Return [min, max] of x, like R’s range(). |
Math
Math operations.
| sign | Return -1, 0, or 1. Vectorised. |
| trunc | Truncate toward zero. Vectorised. |
| ceiling | Ceiling. Vectorised. |
| floor | Floor. Vectorised. |
| sqrt | Square root. Vectorised. |
| log | Natural log, or log to given base. Vectorised. |
| log2 | Log base 2. Vectorised. |
| log10 | Log base 10. Vectorised. |
| exp | e^x. Vectorised. |
| abs | Absolute value. Vectorised. |
| var | Sample variance (ddof=1), like R’s var(). |
| sd | Sample standard deviation, like R’s sd(). |
| mean | Arithmetic mean. Like R’s mean(). |
| median | Median. Like R’s median(). |
| quantile | Sample quantiles, like R’s quantile(). |
| scale | Centre and/or scale x, like R’s scale(). |
| round | Round x to digits decimal places, like R’s round(). |
Files
File and path utilities.
| list_files | List files in a directory, like R’s list.files(). |
| file_exists | Return True if file exists. Like R’s file.exists(). |
| dir_exists | Return True if directory exists. Like R’s dir.exists(). |
| basename | Return filename component of path. Like R’s basename(). |
| dirname | Return directory component of path. Like R’s dirname(). |
| file_path | Construct file paths, like R’s file.path(). |
Table
Tabulation functions.
| table | Frequency table of x, sorted by name, like R’s table(). |
| prop_table | Proportional frequency table, like R’s prop.table(). |
| margin_table | Marginal sums of a contingency table (dict). |
Functional
Functional programming helpers.
| lapply | Apply func to each element of x, return list. Like R’s lapply(). |
| sapply | Apply func to each element of x, simplify if possible. Like R’s sapply(). |
| vapply | Like sapply() but checks that each result is of expected_type. |
| tapply | Apply func to subsets of x grouped by index. Like R’s tapply(). |
| rapply | Recursively apply func to all non-list elements in a nested list. |
| Filter | Return elements of x for which func returns True. Like R’s Filter(). |
| Map | Apply func element-wise across args. Like R’s Map(). |
| Reduce | Reduce x with func. Like R’s Reduce(). |
Inspect
Inspection and summary functions.
| head | Return first n elements, like R’s head(). |
| tail | Return last n elements, like R’s tail(). |
| length | Length of x, like R’s length(). |
| nrow | Number of rows of a list-of-lists. Like R’s nrow(). |
| ncol | Number of columns of a list-of-lists (assumes rectangular). Like R’s ncol(). |
| dim | Return [nrow, ncol] of a list-of-lists. Like R’s dim(). |
| summary | Basic numeric summary, like R’s summary() on a numeric vector. |
| rstr | Compact display of object structure, loosely like R’s str(). |
Utils
Utility helpers.
| vec | Wrap a list or tuple in a vectorised Vec object. |