0
私は、識別子とその他のパラメータといくつかの他のパラメータとクラスを持つ学校を、各クラスの識別子といくつかの他のパラメータと学生と教師を持つ各学校で定義しようとしています。私は各タイプのS4オブジェクトを定義しました。 ieRのs4オブジェクトの効率的な方法は?
student <- setClass(
"student",
slots = c(
identifier = "numeric",
testscore = "numeric",
endAbil = "numeric"
)
)
clss <- setClass(
"class",
slots = c(
identifier = "numeric",
teacher = "teacher",
student = "student",
capacity = "numeric"
)
)
school <- setClass(
"school",
slots = c(
identifier = "numeric",
cls = "matrix",
capacity = "numeric"
)
)
学生の価値を変えた場合、私は学校の中の価値を変えるだけで、学生を学校やクラスにランダムに割り当てます。これらの値を学生に結びつける方法はありますか?また、i番目の学校のj番目の生徒の変数の値を変更すると、生徒の変数も変わります。
Students <- new("student", identifier = sample('#ofStudents'))
[email protected] <-rnorm('#ofStudents',mean = 0 , sd = 1)
# Randomly assign students to classes
ind = 1:'#ofStudents'
# #ofClasses is fixed for all schools
for (i in 1:'#ofSchools'){
for (j in 1:'#ofClasses'){
# get the ith schools' jth class
tmp <- sample(ind,[email protected][i,j][[1]]@capacity)
[email protected][i,j][[1]]@[email protected] <- [email protected][tmp]
[email protected][i,j][[1]]@[email protected] <- [email protected][tmp]
ind = ind [! ind %in% tmp]
}
}