-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72e4d7f
commit 9f7561f
Showing
5 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
##' convert a matrix to a tidy data frame (from wide to long format as described in the tidyverse concetp) | ||
##' | ||
##' | ||
##' @title mat2df | ||
##' @param x the input matrix | ||
##' @return a data.frame in long format with the 'value' column stores the original values and 'row' and 'col' columns stored in row and column index as in x | ||
##' @examples | ||
##' x <- matrix(1:15, nrow = 3) | ||
##' mat2df(x) | ||
##' @export | ||
##' @author Guangchuang Yu | ||
mat2df <- function(x) { | ||
nr <- nrow(x) | ||
nc <- ncol(x) | ||
d <- data.frame( | ||
value = as.vector(x), | ||
row = rep(1:nr, times = nc), | ||
col = rep(1:nc, each = nr) | ||
) | ||
return(d) | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.