与之相关
DATA = data.frame("GROUP" = sort(rep(1:4, 200)),
"TYPE" = rep(1:2, 400),
"TIME" = rep(100:101, 400),
"SCORE" = sample(1:100,r=T,800))
欢呼,
DATA = data.frame("GROUP" = sort(rep(1:4, 200)),
"TYPE" = rep(1:2, 400),
"TIME" = rep(100:101, 400),
"SCORE" = sample(1:100,r=T,800))
Cheers all,
I have 'DATA' and wish to estimation the CORRELATION VALUES of SCORE at each TIME and SCORE and TYPE combination BETWEEN AND WITHIN GROUP in this way:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您想计算每种时间和类型组合的组1-2、1-3、1-4之类的相关性。这是一种方法:
I am assuming you want to compute the correlation between groups 1-2, 1-3, 1-4 and so on for each combination of TIME and TYPE. Here's an approach:
这是一种替代方法,它可以创建
time
,type
的所有唯一组合,并通过交叉加入 group group s group >然后计算得分
的相关性data
的对应子集:说明
data.table
在列上设置键group
,type
和<代码>时间。 键盘以后快速子集是必需的。cj()
创建列的所有唯一组合time
,type> type
,group 和
组
(两次)。 交叉加入的列已重命名,以避免以后的名称冲突。[Groupa&lt; groupB]
确保groupa
和groupb
仅出现一次的等效组合,例如,g2g1
被删除以支持G1G2
。因此,这是一种数据。cortype
通过参考附加。by = .i
)和子集data
by来计算组的相关性。 groupa
,<代码>类型,time
和groupb
,type
,time
,分别使用键
使用快速子集。请,请参阅vignette norofollow noreferrer> 有关更多详细信息。请注意,
by = .i
是data.table
开发版本1.14.3的新功能。data
中不存在的时间,类型和组的组合将出现在结果集中,但以na
在列中标记为corvalue
。数据
Here is an alternative approach which creates all unique combinations of
TIME
,TYPE
, and duplicatedGROUP
s through a cross join and then computes the correlation ofSCORE
for the correspondings subsets ofDATA
:Explanation
DATA
is coerced to classdata.table
while setting a key on columnsGROUP
,TYPE
, andTIME
. Keying is required for fast subsetting later.CJ()
creates all unique combinations of columnsTIME
,TYPE
,GROUP
, andGROUP
(twice). The columns of the cross join have been renamed to avoid name clashes later on.[groupA < groupB]
ensures that equivalent combinations ofgroupA
andgroupB
only appear once, e.g.,G2G1
is dropped in favour ofG1G2
. So, this is kind of data.table version oft(combn(unique(DATA$GROUP), 2))
.corType
is append by reference.by = .I
) and subsettingDATA
bygroupA
,type
,time
andgroupB
,type
,time
, resp., using fast subsetting throughkeys
. Please, see the vignette Keys and fast binary search based subset for more details.Note that
by = .I
is a new feature ofdata.table
development version 1.14.3.Combinations of time, type, and group which do not exist in
DATA
will appear in the result set but are marked byNA
in columncorValue
.Data