ldf_arrange_by_rownames: Rearrange a list of data frames by rownames

View source: R/operations.R

ldf_arrange_by_rownamesR Documentation

Rearrange a list of data frames by rownames

Description

Rearrange a list of data frames by rownames

Usage

ldf_arrange_by_rownames(list_df)

Arguments

list_df

a (non-empty) list of data.frame objects. The data frames must have the same colnames attribute.

Value

a rearranged list of data frames, where the names of the elements of the list_df (the 'ids' of the data frames) and the rownames of the data frames have switched places: the unique row names of the original list's combined data frames serve as names for the returned list of data frames, while the data frame 'ids' (names of the original list's elements) now serve as rownames for the data frames in the new list.

E.g. if in the given list there was a data.frame with id 'A': a = list_df[["A"]] and rownames(a) = c("row1", "row2"), then in the rearranged list there would be two data frames with ids "row1" and "row2", each of them having a row with name "A" where also these data rows would be the same as before: list_df[["A"]]["row1", ] == returned_list[["row1"]]["A",] and list_df[["A"]]["row2", ] == returned_list[["row2"]]["A",] respectively.

Examples

df.1 = data.frame(matrix(data = 0, nrow = 3, ncol = 3,
  dimnames = list(c("row1", "row2", "row3"), c("C.1", "C.2", "C.3"))))
df.2 = data.frame(matrix(data = 1, nrow = 3, ncol = 3,
  dimnames = list(c("row1", "row2", "row4"), c("C.1", "C.2", "C.3"))))
list_df = list(df.1, df.2)
names(list_df) = c("zeros", "ones")
res_list_df = ldf_arrange_by_rownames(list_df)


bblodfon/usefun documentation built on Sept. 17, 2023, 4:37 p.m.