如何在R中找到某个单元格上的值数?

如何在R中找到某个单元格上的值数?,r,dataframe,R,Dataframe,我在R中有一个data.frame,看起来像: percent Input_SNP 9.123 Set_1 8.713 Set_2 7.666 Set_3 7.091 Set_4 7.601 Set_5 5.461 Set_6 9.992 Set_7 5.555 除了我没有超过Input\u SNP的周期。当我调用c

我在R中有一个data.frame,看起来像:

              percent
 Input_SNP      9.123
 Set_1          8.713
 Set_2          7.666
 Set_3          7.091
 Set_4          7.601
 Set_5          5.461
 Set_6          9.992
 Set_7          5.555

除了我没有超过
Input\u SNP
的周期。当我调用
class(data)
时,它是类“data.frame”。我实际上有500套。我想计算哪些集合的值大于或等于我的
Input\u SNP
。在本例中,7个中有1个的值大于或等于my
Input\u SNP
。我想要一个具有此值的输出变量。如何在R中实现这一点

如果您的数据被称为
df
,那么您可以

inp <- rownames(df) == "Input_SNP"
with(df, percent[!inp] > percent[inp])
# [1] FALSE FALSE FALSE FALSE FALSE  TRUE FALSE
对于价值观本身,我们可以这样做

with(df, sum(percent[!inp] > percent[inp]))
# [1] 1
with(df, percent[!inp][percent[!inp] > percent[inp]])
# [1] 9.992
数据:

df <- structure(list(percent = c(9.123, 8.713, 7.666, 7.091, 7.601, 
5.461, 9.992, 5.555)), .Names = "percent", class = "data.frame", row.names = c("Input_SNP", 
"Set_1", "Set_2", "Set_3", "Set_4", "Set_5", "Set_6", "Set_7"
))

df如果您的数据被称为
df
,那么您可以

inp <- rownames(df) == "Input_SNP"
with(df, percent[!inp] > percent[inp])
# [1] FALSE FALSE FALSE FALSE FALSE  TRUE FALSE
对于价值观本身,我们可以这样做

with(df, sum(percent[!inp] > percent[inp]))
# [1] 1
with(df, percent[!inp][percent[!inp] > percent[inp]])
# [1] 9.992
数据:

df <- structure(list(percent = c(9.123, 8.713, 7.666, 7.091, 7.601, 
5.461, 9.992, 5.555)), .Names = "percent", class = "data.frame", row.names = c("Input_SNP", 
"Set_1", "Set_2", "Set_3", "Set_4", "Set_5", "Set_6", "Set_7"
))
df
x=x,1,0)
#百分比
#输入单核苷酸多态性0
#集_1 0
#集合2 0
#集合3 0
#Set_4 0
#第50组
#第6组1
#第70组
x=x,1,0)
#百分比
#输入单核苷酸多态性0
#集_1 0
#集合2 0
#集合3 0
#Set_4 0
#第50组
#第6组1
#第70组

prop.table(表(数据$percent[-1]>=数据$percent[1]))
prop.table(表(数据$percent[-1]>=数据$percent[1])
除了最后的
和(df,percent[!np][percent inp]>percent[inp]])
给了我多个值之外,这是一个较小的附加问题。我现在只使用
p[percent[inp])/(nrow(df)-1)
我知道如何在图形中打印p值。如果p值为0,那么我希望p等于0.002。我怎么做呢?关于你的第一条评论,当
percent[inp]上有多个值时,它会给你多个值
。你在找总数吗?我能正确地得到它。我想要数值更高的比例。谢谢!我的后续行动怎么样,有什么想法吗?除了最后的
和(df,percent[!np][percent[!inp]>percent[inp]])
给了我多个值?这是一个较小的附加问题。我现在只使用
p[percent[inp])/(nrow(df)-1)
我知道如何在图形中打印p值。如果p值为0,那么我希望p等于0.002。我该怎么做?关于你的第一条评论,当有多个值超过
percent[inp]时,它会给你多个值
。你在找总数吗?我能正确地得到它。我想要数值更高的比例。谢谢!我的后续行动怎么样,有什么想法吗?