Title: | Creates an adjacency matrix from a list of strings |
---|---|
Description: | 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. |
Authors: | Tom Drake |
Maintainer: | Tom Drake <[email protected]> |
License: | GPL-3 |
Version: | 0.1.0 |
Built: | 2025-03-06 05:03:28 UTC |
Source: | https://github.com/tomdrake/string2adjmatrix |
Generates a blank adjacency matrix from a specified string
generate_adj_matrix(string_data, data_separator = ",", remove_spaces = F)
generate_adj_matrix(string_data, data_separator = ",", remove_spaces = F)
string_data |
The 'string_data' argument is the string from which the unique values and matrix will be generated. |
data_separator |
The 'data_separator' argument is the chracter separating specified substrings in the given string. Default is ','. |
remove_spaces |
The 'remove_spaces' argument will remove spaces from the header values (thus disrupting the search unless all spaces are removed in the given string in next steps). This is useful for separating strings with an irregular number of spaces between the same substrings. |
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. Data must be provided as a character string.
Tom Drake
##Example library(String2AdjMatrix) #Start with character string 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)
##Example library(String2AdjMatrix) #Start with character string 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)
Creates an adjacency matrix
string_2_matrix(new_matrix, supplied_string, self = 0)
string_2_matrix(new_matrix, supplied_string, self = 0)
new_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. |
supplied_string |
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')' |
self |
The 'self' option specifies how to handle data when the specified object is found within a string. Default is 0. i.e. the adjacency matrix does not count it when the substring is found, only when the substring is found in combination with another unique substring. |
An adjacency matrix
Generating large matrices is computationally intensive and may take a while.
Tom Drake
##Example library(String2AdjMatrix) #Start with character string 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)
##Example library(String2AdjMatrix) #Start with character string 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)