Rでいくつかのデータテーブルの分析を自動化しようとしています.
私は次のようなテーブルを持っています:
シータ 1 シータ 2 シータ 3 シータ 4 シグマ 1 シグマ 2 オメガ 1 オメガ 2 オメガ 3 オメガ 4
ただし、T と O の数は分析によって異なります。そこで、R がシータ、シグマ、オメガの数を自動的に把握し、それらを独自の行列に入れて個別に分析できるように、コードを作成したいと思います。ある種の正規表現を考えていますか?しかし、STATA のコマンドには慣れています。
私は近いと思いますが、これまでのところ私のコードは次のとおりです。
mcmcChain <- as.matrix(MCMC) #switch MCMC object to matrix
mcmcNames <- colnames(mcmcChain) #make vector with column names
mcmcNames
[1] "THETA1" "THETA2" "THETA3" "THETA4" "THETA5" "SIGMA.1.1"
[7] "SIGMA.2.1" "SIGMA.2.2" "OMEGA.1.1" "OMEGA.2.1" "OMEGA.2.2" "OMEGA.3.1"
[13] "OMEGA.3.2" "OMEGA.3.3" "OMEGA.4.1" "OMEGA.4.2" "OMEGA.4.3" "OMEGA.4.4"
[19] "OMEGA.5.1" "OMEGA.5.2" "OMEGA.5.3" "OMEGA.5.4" "OMEGA.5.5" "MCMCOBJ"
nVar <- length(mcmcNames) #number of variables
for (i in 1:nVar) {
thetaNames <- mcmcNames[i] # !!some way to identify only theta's!!
}
nTheta <- length(thetaNames) #n theta variables
thetaSamp <- NULL
for (j in 1:nTheta) { #cbind all thetas to one column
thetaSamp <- cbind(thetaSamp,
mcmcChain[,paste("THETA",j,sep="") ] )
}
助けてくれてありがとう!