# after z-transformation problem with mean-function

#### mike_88

##### New Member
Hey everyone,
i used the scale function to conduct a z-transformation.

i have a question in respect of a problem, calculating a mean of a column. take this data for exampel:
Code:
aV <- c(rnorm(20,0,1))
condition<-rep(c(1:10),2)
index<-rep(c(1:5),4)

df<- data.frame(condition,index,aV)
df$z.aV <- scale(df$aV ,center=TRUE, scale = TRUE)
the result after subsetting:
Code:
> mean(df$z.aV[df$index==2])
[1] -0.3075451
the result after calculating the column-mean
Code:
> mean(df$z.aV) [1] 9.013786e-18 what is wrong here? why does the function mean() calculate this mean 9.013786e-18 when i try to calculate the column mean. the same is true for my original data-set: Code: data$aV    <- scale(data$av, center = TRUE, scale = TRUE) afterwards, i subsetted the data and tried to calculate the mean for this subset when i take a random subset, for example Code: data$aV[data$index==5 & data$condition==1 ]
the output is:
Code:
[1]  0.45603199 -0.55385017  0.25405556  0.25405556 -0.55385017  0.65800842  1.86986702  0.05207912
[9]  0.45603199 -1.15977947
and when i calculate the mean(), it works perfectly

Code:
mean(data$aV[data$index==24 & data$condition==1 ]) Code: [1] 1.73265 butafter i tried to calculate the column-mean, something strange happens Code: mean(data$aV)
Code:
[1] 6.256592e-17
how is that possible? when i calculate all the mean from index 1-23 (out of 24), the mean is still reasonable

Code:
[1] -0.001454894
but as soon as i calculate the column-mean, i get [1] 6.256592e-17

when i only calculate the mean for index 24 separately the mean is reasonable as well:

Code:
[1] 0.03153915
where is the problem here...
I never had this problem before, after a z-transformation...

thank you in advance for your help (!)...i actually have no idea what the problem is here...

#### mike_88

##### New Member
problem after transformation (using scale() ) calculating the mean

Hey everyone,
i used the scale function to conduct a z-transformation.

i have a question in respect of a problem, calculating a mean of a column. take this data for exampel:
Code:
aV <- c(rnorm(20,0,1))
condition<-rep(c(1:10),2)
index<-rep(c(1:5),4)

df<- data.frame(condition,index,aV)
df$z.aV <- scale(df$aV ,center=TRUE, scale = TRUE)
the result after subsetting:
Code:
> mean(df$z.aV[df$index==2])
[1] -0.3075451
the result after calculating the column-mean
Code:
> mean(df\$z.aV)
[1] 9.013786e-18
what is wrong here? why does the function mean() calculate this mean 9.013786e-18 when i try to calculate the column mean. the same is true for my original data-set

where is the problem here...
I never had this problem before, after a z-transformation...

thank you in advance for your help (!)...i actually have no idea what the problem is here...

#### CB

##### Super Moderator
Sorry, your posts were in the Moderator queue for a while waiting approval. Have approved and merged your threads since they seem to be about the same question.

why does the function mean() calculate this mean 9.013786e-18 when i try to calculate the column mean.
I presume this is just because of accuracies inherent in floating point arithmetic. The mean of a variable that has been transformed to a z score is theoretically zero, but some rounding is involved in the intermediate calculations. This means that the displayed mean won't be exactly zero, but instead a number very very close to zero. (Note that 9.013786e-18 is a very small number: 0.000000000000000009).

#### rogojel

##### TS Contributor
As for the subset means l think you see the sampling error. Expecting a mean of a z-transformed subset to be close to zero is equivalent to expecting the mean of the subsample to be close to the mean of the sample - actually it would be surprising if it were so.

regards