How to count the total number of rows in specific range

Hi All,

I need some help here. I would like to count the number of value of specific range from my data set. For example like I would like to know how many rows in my dataset have the value of <10, >10, >20 etc.
Thank you for help
Here some dataset

Time Value
0900 10
0901 -1
0902 50
0903 34
0904 33
0905 2
0906 67
0907 90

The simplest solution for one value would be like the following. Will that work for you?

DF <- read.csv("~/R/Play/Dummy.csv", sep=" ")
DF
  Time Value
1  900    10
2  901    -1
3  902    50
4  903    34
5  904    33
6  905     2
7  906    67
8  907    90
sum(DF$Value > 10) 
[1] 5

Thank you for the code.
I have tried using the same code.
And its appear as 'NA'

How to resolve it please

Try this

library(tidyverse)
iris %>% 
  expand_grid(tibble(Min = seq(5, 7, .1), Max = Min + 0.1)) %>% 
  group_by(Min, Max) %>% 
  summarize(Sepal.Length.Count = sum((Sepal.Length > Min) & (Sepal.Length <= Max)), 
           .groups = "drop")

If there are missing values you want to ignore you need the na.rm = TRUE

library(tidyverse)
iris %>% 
  expand_grid(tibble(Min = seq(5, 7, .1), Max = Min + 0.1)) %>% 
  group_by(Min, Max) %>% 
  summarize(Sepal.Length.Count = sum((Sepal.Length > Min) & (Sepal.Length <= Max), na.rm = TRUE), 
           .groups = "drop")

Alright, thanks..i solved it..I just need to add the 'na.rm=TRUE' to ignore the missing values.

Thank you very much

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.