Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

DataFrame-utils

Common operations on DataFrame objects


Description

Common operations on DataFrame objects.

Merging

In the code snippet below, x is a DataFrame object.

merge(x, y, ...): Merges two DataFrame objects x and y, with arguments in ... being the same as those allowed by the base merge. It is allowed for either x or y to be a data.frame.

Splitting

In the code snippet below, x is a DataFrame object.

split(x, f, drop = FALSE): Splits x into a SplitDataFrameList object, according to f, dropping elements corresponding to unrepresented levels if drop is TRUE.

Looping

In the code snippet below, x is a DataFrame object.

by(data, INDICES, FUN, ..., simplify = TRUE): Apply FUN to each group of data, a DataFrame, formed by the factor (or list of factors) INDICES. Exactly the same contract as as.data.frame.

Subsetting based on NA content

In the code snippets below, x is a DataFrame object.

na.omit(object): Returns a subset with incomplete cases removed.

na.exclude(object): Returns a subset with incomplete cases removed (but to be included with NAs in statistical results).

is.na(x): Returns a logical matrix indicating which cells are missing.

complete.cases(x): Returns a logical vector identifying which cases have no missing values.

Transforming

In the code snippet below, x is a DataFrame object.

transform(`_data`, ...): adds or replaces columns based on expressions in .... See transform.

Statistical modeling with DataFrame

A number of wrappers are implemented for performing statistical procedures, such as model fitting, with DataFrame objects.

Tabulation

xtabs(formula = ~., data, subset, na.action, exclude = c(NA, NaN), drop.unused.levels = FALSE): Like the original xtabs, except data is a DataFrame.

Author(s)

Michael Lawrence

See Also

Examples

## split
sw <- DataFrame(swiss)
swsplit <- split(sw, sw[["Education"]])

## rbind & cbind
do.call(rbind, as.list(swsplit))
cbind(DataFrame(score), DataFrame(counts))

df <- DataFrame(as.data.frame(UCBAdmissions))
xtabs(Freq ~ Gender + Admit, df)

S4Vectors

Foundation of vector-like and list-like containers in Bioconductor

v0.28.1
Artistic-2.0
Authors
H. Pagès, M. Lawrence and P. Aboyoun
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.