r - How to find the sd of two columns of matrix? -



r - How to find the sd of two columns of matrix? -

if have matrix contains 6 variable,if want find sd of (col1 , col1), (col1 , col2), (col1 , col6),......(col6 , col6), , homecoming 6*6 matrix. function should use? (sd: standard deviation)

thanks much.

first, create sample info

set.seed(1) m <- replicate(6, rnorm(5)) # create matrix 6 columns

you can utilize expand.grid possible combinations, loop through combinations using apply. finally, wrap result in matrix

matrix(apply(expand.grid(1:6, 1:6), 1, function(x) sd(m[, x])), ncol=6) # [,1] [,2] [,3] [,4] [,5] [,6] # [1,] 0.9060766593 0.7805859575 1.187979366 0.7326776974 1.0258159472 0.8334359580 # [2,] 0.7805859575 0.6305829418 1.095413861 0.5692800481 0.9169484342 0.6960691132 # [3,] 1.1879793664 1.0954138606 1.413152368 1.0695148355 1.2806974048 1.1228262280 # [4,] 0.7326776974 0.5692800481 1.069514836 0.4382343292 0.8814506207 0.7057912762 # [5,] 1.0258159472 0.9169484342 1.280697405 0.8814506207 1.1324043901 0.9556076127 # [6,] 0.8334359580 0.6960691132 1.122826228 0.7057912762 0.9556076127 0.6643807746

r matrix transpose

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -