从R中另一个S4对象内的S4对象提取信息
我试图使用kmlCov包中的kmlCov()检查一些数据的集群。获得结果后,我不太确定如何从S4对象中提取信息。我认为复杂的原因是,存储信息的S4对象实际上位于另一个S4对象内,我不确定如何获取它 str(objectname)的部分输出如下所示:从R中另一个S4对象内的S4对象提取信息,r,R,我试图使用kmlCov包中的kmlCov()检查一些数据的集群。获得结果后,我不太确定如何从S4对象中提取信息。我认为复杂的原因是,存储信息的S4对象实际上位于另一个S4对象内,我不确定如何获取它 str(objectname)的部分输出如下所示: Formal class 'KmlCovList' [package "kmlcov"] with 1 slots ..@ list_part:List of 2 .. ..$ :Formal class 'GlmCluster' [pack
Formal class 'KmlCovList' [package "kmlcov"] with 1 slots
..@ list_part:List of 2
.. ..$ :Formal class 'GlmCluster' [package "kmlcov"] with 16 slots
.. .. .. ..@ formula :Class 'formula' length 3 Total ~ Prop
.. .. .. .. .. ..- attr(*, ".Environment")=<environment: 0x11aed66e8>
.. .. .. ..@ nClust : num 2
.. .. .. ..@ ident : chr "CaseID"
.. .. .. ..@ timeVar : chr "time"
.. .. .. ..@ time : int [1:8287] 0 1 2 3 4 5 6 7 0 1 ...
.. .. .. ..@ effectVar : chr ""
.. .. .. ..@ effect : NULL
.. .. .. ..@ model.glm :List of 30
.. .. .. .. ..$ coefficients : Named num [1:4] 0.988 2.028 0.948 6.317
.. .. .. .. .. ..- attr(*, "names")= chr [1:4] "Ga" "Gb" "Ga:Prop" "Gb:Prop"
.. .. .. .. ..$ residuals : Named num [1:8287] 4.064 0.634 -1.215 -1.936 -1.936 ...
.. .. .. .. .. ..- attr(*, "names")= chr [1:8287] "1" "2" "3" "4" ...
.. .. .. .. ..$ fitted.values : Named num [1:8287] 1.94 1.37 1.22 1.94 1.94 ...
.. .. .. .. .. ..- attr(*, "names")= chr [1:8287] "1" "2" "3" "4" ...
我获取存储在对象中的所有内容。我尝试过这样的格式
objectname@list_part@formula
objectname@list_part$formula
却没能得到我需要的。我想得到的是存储在插槽中的特定信息
如有任何建议,将不胜感激。谢谢 使用来自
?kmlCov
library(kmlcov)
data(artifdata)
res <- kmlCov(formula = Y ~ clust(time + time2),
data = artifdata, ident = 'id',timeVar = 'time', effectVar = 'treatment',
nClust = 2:3, nRedraw = 2)
lapply(res@list_part, function(x)
lapply(x,function(y) y@formula))
#[[1]]
#[[1]][[1]]
#Y ~ time + time2
#<environment: 0x17a01718>
#[[1]][[2]]
#Y ~ time + time2
#<environment: 0x17928f80>
#[[2]]
#[[2]][[1]]
#Y ~ time + time2
#<environment: 0x26eed80>
#[[2]][[2]]
#Y ~ time + time2
#<environment: 0x1752dc70>
sapply(res@list_part, function(x) sapply(x,function(y) y@nClust))
# [,1] [,2]
#[1,] 2 3
#[2,] 2 3
lapply(res@list_part, function(x)
sapply(x,function(y) coef(y@model.glm)))
库(kmlcov)
数据(人工数据)
res以下答案,您也可以尝试:
str(res)
str(res@list_part[[1]][[1]]@model.glm)
str(res@list_part[[1]][[1]]@model.glm$formula)
res@list_part[[1]][[1]]@model.glm$formula
str(res@list_part[[1]][[2]]@ident)
str(res@list_part[[1]][[2]]@model.glm)
res@list_part[[1]][[2]]@model.glm
简而言之,您可以使用@而不是$从S4对象提取信息
str(res)
str(res@list_part[[1]][[1]]@model.glm)
str(res@list_part[[1]][[1]]@model.glm$formula)
res@list_part[[1]][[1]]@model.glm$formula
str(res@list_part[[1]][[2]]@ident)
str(res@list_part[[1]][[2]]@model.glm)
res@list_part[[1]][[2]]@model.glm