MyNixOS website logo
Description

Creates an Adjacency Matrix from a List of Strings.

Takes a list of character strings and forms an adjacency matrix for the times the specified characters appear together in the strings provided. For use in social network analysis and data wrangling. Simple package, comprised of three functions.
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

String2AdjMatrix

This package has been designed to provide functions which enable the construction of adjacency matrices, from a specified string of characters. It contains functions to generate an empty adjacency matrix (with each unique substring as a row name or column name) from a given list of strings. This is useful when performing social network anaylsis. In this current release, the strings are bidirectional, meaning it doesn't matter where two unique substrings occur in the string.

The output matrices can be used directly with packages such as igraph()

Generating large matrices is computationally intensive and may take a while.

Example

Start with data to generate an adjacency matrix from

string_in = c('apples, pears, bananas', 'apples, bananas', 'apples, pears')

Generate a new blank matrix

blank_matrix = generate_adj_matrix(string_in)

Now fill the matrix

string_2_matrix(blank_matrix, string_in)

Installation instructions

From CRAN - stable release

install.packages('String2AdjMatrix')

From GitHub - development version

devtools::install_github('tomdrake\String2AdjMatrix')

Dependencies

Requires stringr

Overview

This package comprises three functions; generate_adj_matrix, string_2_matrix and string_2_matrix_x.

1. generate_adj_matrix()

Generates an adjacency matrix from a given string. Detects unique values and generates a blank matrix with colnames and rownames of each unique value in supplied string.

The string_data argument is the string from which the unique values and matrix will be generated.

2. string_2_matrix()

Iteratively applies string_2_matrix_x() to each column of a matrix. Use to generate an entire adjacency matrix.

The new_matrix element of the function should be either the matrix generated by generate_adj_matrix() or an empty data matrix of equal number of rows and columns. These should have unique values specified as the row names and column names.

The supplied_string element refers to the string in which the search is to be performed. i.e list = c('apples, pears, bananas', 'apples, bananas', 'apples, pears')

Generating large matrices is computationally intensive and may take a while.

3. string_2_matrix_x()

This function takes a specified column in a matrix and identifies how many times that substring appears with each row name for a given set of strings. Use to generate one column of adjacency data. Also used iteratively as part of string_2_matrix()

The new_matrix element of the function should be either the matrix generated by generate_adj_matrix() or an empty data matrix of equal number of rows and columns. These should have unique values specified as the row names and column names.

The supplied_string element refers to the string in which the search is to be performed. i.e list = c('apples, pears, bananas', 'apples, bananas', 'apples, pears')

The coord_x argument specifies the number column for which to convert. i.e. coord_x = 1 is the first column of a data matrix, coord_x = 12 is the twelfth column of a data matrix.

Metadata

Version

0.1.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows