I am trying to group data based upon dates (all observations taken in a day) and applying a function to count no. of observations in the grouped data.
my code for this purpose is:
Library(ggplot2)
library(lubridate)
library(tidyverse)
cmsaf_data <- read.csv("tmy_era_25.796_45.547_2005_2014.csv",
skip = 16, header = T)
data <- cmsaf_data %>%
mutate(time = mdy_hm(Date_Time),
date = date(time), months = month(date))
data <- subset(data,Global.horizontal.irradiance..W.m2.>0) # subsetting based upon values of GHI > 0
year(data$date) <- 2007
summarised <- data %>%
group_by(date) %>% summarise(hours = nrow(data))
In the last line of this code, I am trying to group data date wise and calculating no. of observations i.e now of rows in my data but the result of this is that instead of getting no. of rows of the particular group, I am getting no. of rows of the whole data.
Previously I have worked on the same code and applied sum function to my grouped data and it was working perfectly! Now when I am trying to apply nrow() function to count no. of rows, this code isn't working.
I am not sure what mistake I am making. If there is any correction that can be done or method that I can follow, please guide me to it!
Link to my data is: link
Thanks in advance!