ecotyper.rcompat.frame

data.frame semantics needed to reproduce EcoTyper’s tables row for row.

Functions

factor_levels(values)

levels(factor(values)): sorted unique non-NA values.

make_names(names[, unique])

make.names(names, unique).

make_unique(names[, sep])

make.unique(names).

r_match(x, table)

match(x, table) → 0-based positions, -1 for no match.

r_merge(x, y, by[, all_x, all_y, suffixes, ...])

merge(x, y, by = by, all.x, all.y) for a single key column.

r_order(*keys[, decreasing])

order(k1, k2, ...) → 0-based stable permutation.

ecotyper.rcompat.frame.r_order(*keys, decreasing=False)[source]

order(k1, k2, ...) → 0-based stable permutation.

Numeric keys may be negated by the caller (order(x, -y)).

Parameters:

decreasing (bool)

Return type:

ndarray

ecotyper.rcompat.frame.factor_levels(values)[source]

levels(factor(values)): sorted unique non-NA values.

Return type:

list

ecotyper.rcompat.frame.r_match(x, table)[source]

match(x, table) → 0-based positions, -1 for no match.

Return type:

ndarray

ecotyper.rcompat.frame.make_names(names, unique=False)[source]

make.names(names, unique).

Parameters:

unique (bool)

Return type:

list[str]

ecotyper.rcompat.frame.make_unique(names, sep='.')[source]

make.unique(names).

Parameters:

sep (str)

Return type:

list[str]

ecotyper.rcompat.frame.r_merge(x, y, by, all_x=False, all_y=False, suffixes=('.x', '.y'), x_factor=False)[source]

merge(x, y, by = by, all.x, all.y) for a single key column.

Rows: matched pairs, then unmatched x, then unmatched y, finally stably ordered by the key (sort = TRUE). Columns: key, remaining x columns, remaining y columns (duplicates suffixed). The row index is reset (R gives 1..n).

x_factor=True: the key of x is a factor (e.g. from as.data.frame(table(..))) and all.y is set. R’s final sort then orders by the integer factor codes: rbind appends the unmatched y keys as new levels after x’s levels, so they stay in y order after the matched rows instead of being sorted alphabetically.

Parameters:
Return type:

DataFrame