mean, colMeans, rowMeans – calc. means
使用例: mean(OBJ,na.rm=T/F)
概要:
mean OBJ全体の平均を計算(欠損値を除外して計算する場合はna.rm=Tとする)
colMeans 列毎にOBJの平均を計算(e.g. 変数毎の平均)
rowMeans 行毎にOBJの平均を計算(e.g. 被験者毎の平均)
関連: var, sd
# usage # mean(OBJ) colMeans(OBJ) rowMeans(OBJ) ##### ----- examples ----- ##### > datMat<-matrix(rnorm(10),ncol=2) > datMat [,1] [,2] [1,] -1.1604860 0.09106227 [2,] -0.3358416 0.36780023 [3,] 0.1917609 -0.62506053 [4,] -0.9900861 -0.86436989 [5,] -0.9549163 -2.05218273 > mean(datMat) #10個の数値の平均 [1] -0.633232 > colMeans(datMat) #列ごとの平均(e.g. 変数毎の平均) [1] -0.6499138 -0.6165501 > rowMeans(datMat) #行ごとの平均(e.g. 被験者毎の平均 [1] -0.53471189 0.01597933 -0.21664982 -0.92722799 -1.50354951 # 欠損値がある場合の例 > datMat[1,1]=NaN > datMat [,1] [,2] [1,] NaN 0.09106227 [2,] -0.3358416 0.36780023 [3,] 0.1917609 -0.62506053 [4,] -0.9900861 -0.86436989 [5,] -0.9549163 -2.05218273 > mean(datMat) [1] NaN > mean(datMat,na.rm=T) [1] -0.5746482 > colMeans(datMat) [1] NaN -0.6165501 > colMeans(datMat,na.rm=T) [1] -0.5222708 -0.6165501 > rowMeans(datMat) [1] NaN 0.01597933 -0.21664982 -0.92722799 -1.50354951 > rowMeans(datMat,na.rm=T) [1] 0.09106227 0.01597933 -0.21664982 -0.92722799 -1.50354951 ##### ----- end examples ----- #####