计算一列中的正数和负数 [英] Count the number of positive and negative numbers in a column

查看:80
本文介绍了计算一列中的正数和负数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算数据帧的一列中正值和负值的数量.在R中我该怎么办?

I want to count the number of positive and negative values in one of the columns of the data frame. How would I do in R?

例如,以下是数据框

              logFC   logCPM       LR       PValue          FDR
Bra15066  -5.630822 5.184586 73.79927 8.647868e-18 4.060866e-13
Bra18809 -13.227825 7.158572 72.13478 2.009902e-17 4.719048e-13
Bra45310  5.848073 5.244367 65.61483 5.482472e-16 8.581530e-12
Bra44666  -4.270590 4.852193 63.75671 1.407731e-15 1.652605e-11
Bra34292 -12.917379 4.198073 61.84715 3.711794e-15 3.485968e-11
Bra38258  -5.239433 4.816886 57.98476 2.641567e-14 2.067378e-10

现在我想计算logFC列中与负值相比的正值数量.

Now I would like to count the number of positive values in logFC column compared to negative values.

基本上,对于上述df,我希望看到5个负数计数和1个正数计数.在R中我该怎么办?

Basically I would like to see 5 counts for negative numbers and 1 for positive number for the above df. How would I do in R?

推荐答案

这是一个更简单的解决方案:

Here's an even simpler solution:

table(sign(mydf$logFC))

-1 1 结果的数量分别是您的负数和正数.

The number of -1 and 1 results are your negative and positive counts, respectively.

这篇关于计算一列中的正数和负数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆