(x <- matrix(c(1,0.2,0.5,1.2,0.2,2,0.5,1,0.5,0.5,3,1.6,1.2,1,1.6,4), nrow = 4))
[,1] [,2] [,3] [,4]
[1,] 1.0 0.2 0.5 1.2
[2,] 0.2 2.0 0.5 1.0
for i in {1..10}; do echo -n "Hi"; done |
sudo apt-get update && sudo apt-get install -y --no-install-recommends r-base # Install R
sudo apt-get -y install libcurl4-openssl-dev libssl-dev make g++ # Install dependencies for arrow package
sudo R -e "install.packages('arrow', dependencies=TRUE)" # Install R package arrow
vec2symmat <- function(x) {
mat.dim <- (sqrt(1 + 8*length(x)) - 1)/2
if(mat.dim != round(mat.dim)) stop("The vector length does not match with a square matrix dimension.")
output <- matrix(0, nrow= mat.dim, ncol=mat.dim)
rownum <- colnum <- c()
for(i in 1:mat.dim)
{
The R "stats" package provides the cov2cor
function. However, there is no cor2cov
function available.
cor2cov <- function(cor.mat, var.vec) {
# Check inputs
stopifnot(isSymmetric(cor.mat))
stopifnot(identical(diag(cor.mat), rep(1, length(diag(cor.mat)))))
stopifnot(is.vector(var.vec))