# [R] centering matrix

Wed Jan 30 01:31:00 CET 2013

```Hello,

Please keep the discussion on the R-Help list, there's no reason not to.
As for your question, can you be more specific?
Also, take a look at function ?scale.

Em 29-01-2013 23:31, Eleonora Schiano escreveu:
> i have to do multidimensional scaling.
> Can you help me?
>
>
>
>> Hello,
>>
>> The question is a bit confusing.
>> If you nedd to compute B = X'X, all you have to do is
>>
>> B <- t(X) %*% X
>>
>> If you want to compute the other formula, the following avoids loops.
>>
>> n <- nrow(d)
>> B <- -d^2/2 - rowSums(d^2)/n - colSums(d^2)/n + sum(d^2)/n^2
>>
>>
>> Hope this helps,
>>
>>
>> Em 28-01-2013 22:35, Eleonora Schiano escreveu:
>>
>>> I have a matrix d representing distances.
>>> I need to find B=X'X
>>> X=matrix that generated these distances.+
>>>
>>> B[i,j]=-(1/2)*{[d[i,j]^2-[(1/**n)*sum for i=1...n(d[i,j])^2]-[(1/n)sum
>>> for
>>> j=1...n(d[i,j])^2]+[(1/n^2)sum for i=1...n sum for j=1...n (d[i,j])^2]}
>>>
>>> it's right if i do
>>> B=matrix(,nrow=dim(d),ncol=**dim(d))
>>> for (i in 1:dim(d))
>>> for (j in 1:dim(d)){
>>> B=(-(1/2))*(d[i,j]^2-d[i,]^2-**d[,j]^2+d[,]^2)
>>> }
>>> or i have to put
>>> B[i,j]=(-(1/2))*(d[i,j]^2-d[i,**]^2-d[,j]^2+d[,]^2)
>>> ??
>>>
>>>          [[alternative HTML version deleted]]
>>>
>>> ______________________________**________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>