Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在R studio中查找向量中的正值数?_R_Vector_Count - Fatal编程技术网

如何在R studio中查找向量中的正值数?

如何在R studio中查找向量中的正值数?,r,vector,count,R,Vector,Count,我正在处理大约3000个条目的大向量,我想知道这些条目中有多少是正值。我不确定使用什么函数/代码来确定这一点。在检查哪些值大于0后,取布尔值之和。这种方法之所以有效,是因为TRUE将被强制为1,FALSE将被强制为0 x = -10:10 sum(x > 0) 假设向量名为v: # To see how many of them are positive sum(v > 0) # Indexing the ones that are positive v[v > 0] s

我正在处理大约3000个条目的大向量,我想知道这些条目中有多少是正值。我不确定使用什么函数/代码来确定这一点。

在检查哪些值大于
0
后,取布尔值之和。这种方法之所以有效,是因为
TRUE
将被强制为
1
FALSE
将被强制为
0

x = -10:10
sum(x > 0)

假设向量名为
v

# To see how many of them are positive
sum(v > 0)

# Indexing the ones that are positive
v[v > 0]
sum(x>0)
其中
x
是向量