R 使用带有 LD 功能的 Taply
我正在尝试使用遗传学包中的 LD() 函数执行连锁不平衡计算。对于那些不知道的人,它的写法如下:
g1=genotype(a)
g2=genotype(b)
LD(g1,g2)
其中 a 和 b 是字符
鉴于此,我有一个包含 4 列和大量行的数据框,我试图找到其中 2 列的 LD 。假设 df$col3 和 df$col4 代表上面示例中的 a 和 b,我将如何执行计算?
我正在考虑使用 tapply,因为 for 循环将永远持续下去:
tapply(df$col3,df$col4,function)
问题是我无法找到一种方法来为它们所在的特定行设置以下内容:
g1=genotype(row "n", col3)
g2=genotype(row "m", col4)
我知道“行'n'”是不是实际有效的代码;我只是不知道还能如何描述它。
最后,我计划在设置 g1 和 g2 后运行 LD 计算
I am trying to perform a linkage disequilibrium calculation using the LD() function from the genetics package. For those who don't know, it is written as follows:
g1=genotype(a)
g2=genotype(b)
LD(g1,g2)
where a and b are characters
Given that, I have a dataframe with 4 columns and a large number of rows and I'm trying to find the LD of 2 of the columns. Assuming df$col3 and df$col4 represent a and b from the above example, how would I go about performing the calculation?
I was considering using tapply, as a for loop would take forever:
tapply(df$col3,df$col4,function)
The problem is that I can't figure out a way to set the following for the specific rows that they are in only:
g1=genotype(row "n", col3)
g2=genotype(row "m", col4)
I know the "row 'n'" is not an actual valid code; I just didn't know how else to describe it.
In the end, I plan on running the LD calculations once I can set the g1 and g2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如詹姆斯在评论中所说,您可能需要
maply
。我没有您的数据,但这应该可行:我将其制作为社区维基,因为答案是基于评论,而不是我的评论。
As James states in his comment you may want
mapply
. I don't have your data but this should work:I made it community wiki cause answer is based on, not my, comment.