-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauxilaryFunctions.R
More file actions
47 lines (36 loc) · 1004 Bytes
/
Copy pathauxilaryFunctions.R
File metadata and controls
47 lines (36 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Written by Micha³ Makowski
require(reshape2, quietly = TRUE) # melt
source("lambdas.R")
# Melts matrix into 3-column DF
meltingMatrix <- function(matrix,
index = NULL)
{
colnames(matrix) <- seq_len(NCOL(matrix))
rownames(matrix) <- seq_len(NROW(matrix))
matrix <- melt(matrix)
if(!is.null(index))
matrix <- cbind(matrix, index)
return(matrix)
}
# Simple upper triangle function
upper <- function(input)
{
return(input[upper.tri(input, diag = FALSE)])
}
# Round data frame
round_df <- function(x, digits) {
# round all numeric variables
# x: data frame
# digits: number of digits to round
numeric_columns <- sapply(clusterTiming, mode) == 'numeric'
x[numeric_columns] <- round(x[numeric_columns], digits)
x
}
# Adjacent matrix conversion
properAdjacent <- function(input)
{
output <- as.matrix(input != 0)
if(sum(diag(output)) == 0)
diag(output) <- TRUE
return(output)
}