attr2mat: Convert attribute vector to a matrix

Description Usage Arguments Details Value Examples

View source: R/attr2mat.R

Description

attr2mat converts a vector indicating attribute to a matrix

Usage

1
attr2mat(attr, method = "match", diag.val = 0)

Arguments

attr

vector of input attribute (numeric or logical vector).

method

"match", "match.one", "diff", "abs.diff", "sqd.diff", "sum", "product", "identity", "row", "column", "max", "min" or "mean". Default is "match".

diag.val

the diag value to be filled. If NULL is set, no value is inputed.

Details

This function convertes a vector of matrices attr to a new matrix mat[i,j] based on the definition set by method:

"match"(matching the value): Matrix[i,j] = 1 if attr[i] = attr[j]; 0 otherwise.

"match.one"(maching the value 1): Matrix[i,j] = 1 if attr[i] = attr[j] = 1; 0 otherwise.

"diff"(difference): Matrix[i,j] = attr[i] - [j].

"abs.diff"(absolute difference): Matrix[i,j] = |attr[i] - attr[j]|.

"sqd.diff"(squared difference): Matrix[i,j] = (attr[i] - attr[j]=1)^2.

"sum"(sum): Matrix[i,j] = attr[i] + attr[j] = 1.

"product"(product): Matrix[i,j] = attr[i] * attr[j].

"identity"(identity coefficient): Matrix[i,j] = 2 * (attr[i] * attr[j])/(attr[i]^2 + attr[j]^2.

"row"(duplicating row actors' attributes: sender effect): Matrix[i,j] = attr[i].

"column"(duplicating column actors' attributes: receiver effect): Matrix[i,j] = attr[j].

"max"(maximam value): Matrix[i,j] = max(attr[i], attr[j]).

"min"(minimum value): Matrix[i,j] = min(attr[i], attr[j]).

"mean"(mean value): Matrix[i,j] = mean(attr[i], attr[j]).

Value

a matrix converted from a vector.

Examples

1
2
3
4
5
vec <- c(1,1,2,2,3,3)
names(vec) <- letters[1:6]
attr2mat(vec)
attr2mat(vec, "match.one")
attr2mat(vec, "match.one", diag.val = NULL)

huhn1234/vogeltools documentation built on Jan. 17, 2020, 5:21 p.m.