1. In the R language, how to find the number that satisfies the condition?
For example, given a vector c2. Required to find numbers greater than 0:
> C2
[1] 0.00 0.00 0.00 0.00 0.00 0.00 0.06 0.09 0.20 0.09 0.08 0.14 0.14 0.23
[15] 0.08 0.06 0.12 0.20 0.14 0.11 0.20 0.14 0.17 0.15 0.18 0.15 0.20 0.12
[29] 0.23 0.08 0.12 0.08 0.23 0.12 0.08 0.17 0.18 0.17 0.12 0.17 0.14 0.18
[43] 0.11 0.27 0.06
> C2[c2>0]
[1] 0.06 0.09 0.20 0.09 0.08 0.14 0.14 0.23 0.08 0.06 0.12 0.20 0.14 0.11
[15] 0.20 0.14 0.17 0.15 0.18 0.15 0.20 0.12 0.23 0.08 0.12 0.08 0.23 0.12
[29] 0.08 0.17 0.18 0.17 0.12 0.17 0.14 0.18 0.11 0.27 0.06
>
2. Find the number that satisfies the condition, but how to get the position (or index) of these numbers in the original vector?
The answer is to use the which () function.
First find a sequence that satisfies more than 0:
> c2>0
[1] False to False false false true true if True
True True True if True True True True True true to true True
True True True if True True True True True True True True
[PNS] True True True to true true True True
Secondly, it is identified by the series. You will be able to find the appropriate index.
> which (c2>0)
[1] 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
[25] 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
3. Find inference (1) infer that at least one number satisfies a condition
For example, there is at least one number in the inferred vector that is less than or equal to zero
> Any (c2<=0)
[1] TRUE
(2) Infer that all the numbers meet the conditions
For example, infer that all the numbers are greater than 0, infer that all the numbers are greater than or equal to 0:
> All (c2>0)
[1] FALSE
> All (c2>=0)
[1] TRUE
>
R language-Find the number that satisfies the condition and get the index