[R] computing standard deviation in R and in Python
Bogdan Tanasa
t@n@@@ @end|ng |rom gm@||@com
Fri May 24 12:27:45 CEST 2019
Dear all, please would you advise :
do python and R have different ways to compute the standard deviation (sd) ?
for example, in python, starting with :
a = np.array([[1,2,3], [4,5,6], [7,8,9]])
print(a.std(axis=1)) ### per row : [0.81649658 0.81649658 0.81649658]
print(a.std(axis=0)) ### per column : [2.44948974 2.44948974 2.44948974]
# and in R :
z <- matrix(c(1,2,3,4,5,6,7,8,9), nrow=3, ncol=3, byrow=T)
# z# [,1] [,2] [,3]#[1,] 1 2 3#[2,] 4 5 6#[3,] 7 8 9
# apply(z, 1, sd)
sd(z[1,]) #1
sd(z[2,]) #1
sd(z[3,]) #1
# apply(z, 2, sd)
sd(z[,1]) #3
sd(z[,2]) #3
sd(z[,3]) #3
[[alternative HTML version deleted]]
More information about the R-help
mailing list