Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a variable (Var) which stores 10000 values and is of integer nature.

I want to count, how many times 1000 or higher than 1000 numeric value occurs in this list.

Any one liner in R?

Thank you in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
384 views
Welcome To Ask or Share your Answers For Others

1 Answer

sum(Var >= 1000) will do it, as long as Var is a vector. If not, you'll need to tell R to find Var inside whatever object contains it. Here is an example:

> set.seed(2)
> Var <- sample(900:1100, 10)
> Var
 [1]  937 1040 1014  933 1085 1084  925 1061  990 1005
> Var >= 1000
 [1] FALSE  TRUE  TRUE FALSE  TRUE  TRUE FALSE  TRUE FALSE  TRUE
> sum(Var >= 1000)
[1] 6

This uses the fact that TRUE = 1 and FALSE = 0.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...