[R] R WRONG CALCULATIONS - Please Help

JORGE COLACO j_colaco at utad.pt
Mon Sep 14 17:11:57 CEST 2015


I would greatly appreciate if you could let me know why the R does not make
the right computations in the case below.
Waiting for your reply
Jorge Colaço






R version 3.2.2 (2015-08-14) -- "Fire Safety"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: i386-w64-mingw32/i386 (32-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> X<-matrix(c(-1,0,1,-1,1,0,
+ 0,0,1,1,1,-1,
+ -1,0,-1,1,0,1,
+ 1,1,-1,-1,0,0,
+ 0,0,1,1,-1,1),nrow=5,ncol=6,byrow=T)

>
mean<-c(mean(X[,1]),mean(X[,2]),mean(X[,3]),mean(X[,4]),mean(X[,5]),mean(X[,6]))
> mean
[1] -0.2  0.2  0.2  0.2  0.2  0.2
> X-mean
     [,1] [,2] [,3] [,4] [,5] [,6]
[1,] -0.8 -0.2  0.8 -1.2  0.8 -0.2
[2,] -0.2  0.2  0.8  0.8  0.8 -1.2
[3,] -1.2 -0.2 -0.8  0.8 -0.2  0.8
[4,]  0.8  0.8 -1.2 -0.8 -0.2 -0.2
[5,] -0.2 -0.2  0.8  0.8 -0.8  0.8
>

Right Result Should Be:

ans =
  -0.80000  -0.20000   0.80000  -1.20000   0.80000  -0.20000
   0.20000  -0.20000   0.80000   0.80000   0.80000  -1.20000
  -0.80000  -0.20000  -1.20000   0.80000  -0.20000   0.80000
   1.20000   0.80000  -1.20000  -1.20000  -0.20000  -0.20000
   0.20000  -0.20000   0.80000   0.80000  -1.20000   0.80000

	[[alternative HTML version deleted]]



More information about the R-help mailing list