順序なしカテゴリのN個の軸が作る多次元分割表の空間配置

  • 予定パッケージ名
  • 関数名
    • CategoryVectorND
  • タイトル
CategoryVectorND
  • 説明
N1xN2x...xNkテーブルは(N1-1)x(N2-1)x...x(Nk-1)自由度。N1xN2x...xNkテーブルを(N1-1)x(N2-1)x...x(Nk-1)次元空間上の点に対応付ける
  • 使用例
v<-c(3,4,5)
CategoryVectorND(v)
  • ソース
CategoryVectorND<-function(v=c(2,3,4)){
	cvs<-NULL
	for(i in 1:length(v)){
		cvs[[i]]<-CategoryVector(v[i])
	}

	mm<-NULL
	counter<-rep(0,length(v))
	loop<-TRUE
	cnt<-1
	ns<-NULL
	while(loop){
		ns[[cnt]]<-counter+1

		tmp<-cvs[[1]][counter[1]+1,]
		for(i in 2:length(v)){
			tmp<-outer(tmp,cvs[[i]][counter[i]+1,],"*")
		}
		mm[[cnt]]<-c(tmp)

		#print(counter)
		cnt<-cnt+1


		counter<-counterplus(counter,v)
		if(sum(counter)==0){
			loop<-FALSE
		}
	}

	list(ind=ns,coords=mm)
}
  • Rdファイル
\name{CategoryVectorND}
\alias{CategoryVectorND}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{
CategoryVectorND
}
\description{
N1xN2x...xNkテーブルは(N1-1)x(N2-1)x...x(Nk-1)自由度。N1xN2x...xNkテーブルを(N1-1)x(N2-1)x...x(Nk-1)次元空間上の点に対応付ける
}
\usage{
v<-c(3,4,5)
CategoryVectorND(v)
}
%- maybe also 'usage' for other objects documented here.
\details{
%%  ~~ If necessary, more details than the description above ~~
}
\value{
\item{ind}{軸のカテゴリ番号を表すベクトル}
\item{coords}{位置座標}
}
\references{
%% ~put references to the literature/web site here ~
}
\author{
%%  ~~who you are~~
}
\note{
%%  ~~further notes~~
}

%% ~Make other sections like Warning with \section{Warning }{....} ~

\seealso{
}
\examples{
v<-c(3,4)
xx<-CategoryVectorND(v)
# 位置座標を行列にする
xx2<-matrix(unlist(xx$coords),ncol=prod(v-1),byrow=TRUE)
dim(xx2)
# CategoryVector2Dにはv[2],v[1]の順に値を与えると、同一の結果が返る
yy<-CategoryVector2D(v[2],v[1])
yy-xx2
}
  • 参考
    • ベクトルの成分を算出するだけであれば、outer積の繰り返しのみで可能
CategoryVectorND2<-function(v=c(2,3,4)){
	cvs<-NULL
	for(i in 1:length(v)){
		cvs[[i]]<-CategoryVector(v[i])
	}
	mm<-cvs[[1]]
	for(i in 2:length(v)){
		mm<-outer(mm,cvs[[i]],"*")
	}
	mm
}