I didn’t know this either!
I have been working with R for some time now, but once in a while, basic functions catch my eye that I was not aware of…
For some project I wanted to transform a correlation matrix into a covariance matrix. Now, since cor2cov does not exist, I thought about “reversing” the cov2cor function (stats:::cov2cor).
Inside the code of this function, a specific line jumped into my retina:
What’s this [ ]?
Well, it stands for every element $latex E_{ij}$ of matrix $latex E$. Consider this:
> mat
[,1] [,2] [,3] [,4] [,5]
[1,] NA NA NA NA NA
[2,] NA NA NA NA NA
[3,] NA NA NA NA NA
[4,] NA NA NA NA NA
[5,] NA NA NA NA NA
With the empty bracket, we can now substitute ALL values by a new value:
> mat [,1] [,2] [,3] [,4] [,5] [1,] 1 1 1 1…
View original post 55 more words
Posted on February 1, 2013, in Uncategorized. Bookmark the permalink. Leave a comment.
Leave a comment
Comments 0