davidcarslaw / openair

Tools for air quality data analysis
https://davidcarslaw.github.io/openair/
GNU General Public License v2.0
307 stars 113 forks source link

[Question]: When importing data to open air what format should the date be in to run the time variation function? #337

Closed georgiamurphy17 closed 1 year ago

georgiamurphy17 commented 1 year ago

Please ask your question about openair. This could be about how to properly use openair functions, interpret plots, or something else entirely.

Before you submit your issue, it may be useful to check through the openair book just to make sure your question hasn't already been answered!

Feel free to delete these instructions before you submit your issue.


Your question, with example code/reprex if appropriate.

jack-davison commented 1 year ago

Hi Georgia,

You need to make sure R understands that your date column is called date and is in the proper date(time) format.

library(openair)

class(mydata$date)
#> [1] "POSIXct" "POSIXt"
timeVariation(mydata)

The {lubridate} package is useful for properly formatting dates as dates / date-times.


## how do I format my date properly?
char_date <- "31/05/2020 10:00"
class(char_date)
#> [1] "character"
dttm_date <- lubridate::dmy_hm(char_date)
class(dttm_date)
#> [1] "POSIXct" "POSIXt"

Created on 2023-03-18 with reprex v2.0.2

If you have some specific data you're interested in working with, feel free to provide some of it. You may find the dput() function useful for this, or you can attach a small csv file here. See our guide for sharing data.