Skip to content

Commit 3a1c969

Browse files
authored
Merge pull request #59 from jhollway/develop
Added projection functions
2 parents f995465 + 124c678 commit 3a1c969

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: roctopus
22
Title: Utility functions for multimode and multilevel network analysis
3-
Version: 0.2.3
3+
Version: 0.2.4
44
Description: This package assembles a number of utility functions for
55
loading, visualising, and analysing multimode, multiplex, and multilevel networks.
66
URL: https://bitbucket.org/jhollway/roctopus/

NAMESPACE

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
export(col_project)
34
export(create_lattice)
45
export(create_match)
56
export(create_nest)
@@ -11,6 +12,7 @@ export(plot_globalnet)
1112
export(plot_multilevel)
1213
export(plot_twomode)
1314
export(project_list)
15+
export(row_project)
1416
export(threemode_clustering)
1517
export(twomode_2x2)
1618
export(twomode_centralization_between)

NEWS.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# roctopus 0.2.4
2+
3+
2020-07-19
4+
5+
## Package
6+
7+
* Added `row_project()` and `col_project()` functions to make it easier to remember project directions
8+
19
# roctopus 0.2.3
210

311
2020-07-19

R/mm_conversion.R

+18-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ project_list <- function(eventlist){
8282
out
8383
}
8484

85-
8685
#' Transform a data frame to an adjacency or incidence matrix
8786
#'
8887
#' @param df a data frame, with the first column ID
@@ -94,3 +93,21 @@ df_to_mat <- function(df){
9493
df[,1] <- NULL
9594
as.matrix(df)
9695
}
96+
97+
#' Project two-mode matrix into one-mode matrix
98+
#'
99+
#' @name project
100+
#' @usage row_project(OverSxP)
101+
#' @param mat a matrix
102+
#' @return a matrix
103+
#' @export
104+
row_project <- function(mat){
105+
mat %*% t(mat)
106+
}
107+
108+
#' @rdname project
109+
#' @usage col_project(OverSxP)
110+
#' @export
111+
col_project <- function(mat){
112+
t(mat) %*% mat
113+
}

tests/testthat/test_project.R

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
context('projection functions')
2+
3+
mat1 <- matrix(c(0,1,1,0,0,1,1,1),2,4)
4+
mat2 <- matrix(c(2,1,1,3),2,2)
5+
mat3 <- matrix(c(1,0,1,1,0,1,0,1,1,0,1,1,1,1,1,2),4,4)
6+
7+
test_that("matrix projected correctly by rows",{
8+
expect_equal(row_project(mat1), mat2)
9+
})
10+
11+
test_that("matrix projected correctly by columns",{
12+
expect_equal(col_project(mat1), mat3)
13+
})

0 commit comments

Comments
 (0)