Learn R Programming

Boom (version 0.9.15)

match_data_frame: MatchDataFrame

Description

Given two data frames with the same data, but with rows and columns in potentially different orders, produce a pair of permutations such that data2[row.permutation, column.permutation] matches data1.

Usage

MatchDataFrame(data.to.match, data.to.permute)

Value

Returns a list with two elements.

column.permutation

A vector of indices such that the columns of data2[, column.permutation] match the columns of data1. The matching is based on column names.

row.permutation

A vector of indices such that the rows of data2[row.permutation, column.permutation] match the rows of data1. The matching is done by converting rows to strings, and matching the strings.

Arguments

data.to.match

The data frame to be matched.

data.to.permute

The data frame to be permuted.

Author

Steven L. Scott steve.the.bayesian@gmail.com

Examples

Run this code
 x1 <- data.frame(larry = rnorm(10), moe = 1:10, curly = rpois(10, 2))
 x2 <- x1[c(1:5, 10:6), c(3, 1, 2)]

 m <- MatchDataFrame(x1, x2)
 x2[m$row.permutation, m$column.permutation] == x1  ## all TRUE

Run the code above in your browser using DataLab