开发者

R Using Tapply with LD function

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


As James states in his comment you may want mapply. I don't have your data but this should work:

mapply(
     function(a, b) LD(genotype(a), genotype(b)),
     a = df$col3,
     b = df$col4
)

I made it community wiki cause answer is based on, not my, comment.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜