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

tidymat

Conversion between tidy table and named matrix


Description

Convenient fucntions to implement conversion between tidy table and named matrix.

Usage

mat_df(m)

df_mat(df, row, col, value)

Arguments

m

A matrix

df

A data.frame with at least 3 columns, one for row name, one for column name, and one for values. The names for column and row should be unique.

row

Unquoted expression of column name for row

col

Unquoted expression of column name for column

value

Unquoted expression of column name for values

Value

For mat_df, a data.frame. For df_mat, a named matrix.

Examples

mm = matrix(c(1:8,NA),ncol = 3,dimnames = list(letters[1:3],LETTERS[1:3]))
mm
tdf = mat_df(mm)
tdf
mat = df_mat(tdf,row,col,value)
setequal(mm,mat)

tdf %>%
  setNames(c("A","B","C")) %>%
  df_mat(A,B,C)

tidyft

Tidy Verbs for Fast Data Operations by Reference

v0.4.5
MIT + file LICENSE
Authors
Tian-Yuan Huang [aut, cre] (<https://orcid.org/0000-0002-3591-4203>)
Initial release

We don't support your browser anymore

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