优化应用函数输出
我有以下功能:
library (reshape)
phenotype <- rnorm (100)
data <- matrix(rnorm(1000), nrow = 10, ncol=100)
spearman.p <-
reshape(
melt(
apply(data, 1, function(y){
cor.test(y,phenotype,method="spearman")
}[c("p.value", "estimate")]
)
), timevar="L2", idvar="L1", direction="wide"
)
我想知道是否有一种更有效的方法可以从“apply”ed cor.test 中获取 p.value 和估计
有人可以提供一些建议吗?
I have the following function:
library (reshape)
phenotype <- rnorm (100)
data <- matrix(rnorm(1000), nrow = 10, ncol=100)
spearman.p <-
reshape(
melt(
apply(data, 1, function(y){
cor.test(y,phenotype,method="spearman")
}[c("p.value", "estimate")]
)
), timevar="L2", idvar="L1", direction="wide"
)
that I would like to know if there is a more efficent way of getting out the p.value and estimate from a "apply"ed cor.test
Can anyone provide some suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我目前能想到的最好的办法。
This is the best I can come up with at the moment.
这将更加紧凑,并提供来自重复数据的 p.values。这是您想要的吗?:
编辑:如果您正在寻找速度和/或轻松传输到面向并行的平台的可能性,请将其添加到候选列表中:
This would be more compact and delivers the p.values from the duplicated data. Is that what you wanted?:
Edit: If you are looking for speed and/or the possibility of easily transporting to parallel-oriented platforms then add this to the list of candidates: