I have a dataframe like this one:
df <- as.data.frame(matrix(runif(n=45, min=1, max=10), nrow=5))
colnames(df) <- c("CT1|CT1", "CT1|CT2", "CT1|CT3",
"CT2|CT1", "CT2|CT2", "CT2|CT3",
"CT3|CT1", "CT3|CT2", "CT3|CT3")
rownames(df) <- c("A", "B", "C", "D", "E")
Column names consist of a source and target names divided by "|"
CT1|CT1 CT1|CT2 CT1|CT3 CT2|CT1 CT2|CT2 CT2|CT3 CT3|CT1 CT3|CT2 CT3|CT3
A 1.556076 7.928573 7.997007 3.404986 4.063141 8.446360 4.701470 5.767476 7.234584
B 2.853771 5.479293 9.412347 4.475027 5.338721 7.016201 8.388517 8.104206 5.298577
C 2.589011 7.458567 2.909283 1.120513 6.396092 8.148159 6.823542 1.209981 8.750885
D 7.183206 9.927155 6.865064 4.441492 5.441872 1.971493 8.046395 5.295071 4.942874
E 4.456933 4.420317 2.129996 8.827218 2.675958 7.513399 5.977327 7.590824 3.203175
I need to create a list of adjacency matrices for each row of df. For example, for row A the adjacency matrix should look like this:
CT1 CT2 CT3
CT1 1.556076 7.928573 7.997007
CT2 3.404986 4.063141 8.446360
CT3 4.701470 5.767476 7.234584
Base R:
This prints
If you need it as a list include
asplittidyverse:
You can then split this into groups