Questions tagged [padr]

The padr tag refers to the package(padr), in the R programming language. Use this tag for questions regarding this package. The subjects of questions generally asked about this tag are: missing data in time series, N/A values in time series, time interval checks, padding data, and date time formatting & analysis. Use this tag if you are using the functions pad() or thicken(). Please use this tag in conjunction with the tag, r.

The package "padr" is very useful for date-time data sets. It can be used to "fill in the blanks" (with N/A values), in time and date series.

The function pad() allows the user to search through their data frame by many variables, ex. 15 minutes, 1 day, 1 month etc. When the function finds a change in time longer than the user specified interval it assigns it an N/A value.

These N/A values can be replaced later on using functions such as "na.locf" from the "zoo" package, or can just be used to see where ones' data is missing.

Example:

library(padr)

#Example Dates
datetime<-c(Sys.Date(),Sys.Date()+2,Sys.Date()+3,Sys.Date()+5)

#Example Data
data<-c(1,2,3,4)

#Create Df
Df<-data.frame(datetime,data)


#We can see we are missing two dates here!
>Df
    datetime data
1 2017-08-16    1
2 2017-08-18    2
3 2017-08-19    3
4 2017-08-21    4

#Default Pad function has interval='day'
pad(Df)

#Now padded data

pad applied on the interval: day

>Df
datetime data
1 2017-08-16    1
2 2017-08-17   NA
3 2017-08-18    2
4 2017-08-19    3
5 2017-08-20   NA
6 2017-08-21    4

Here is a slightly more complex example using a 15 minute interval

#Example Dates
Dates<-c("2012-09-28 08:00","2012-09-28 08:15","2012-09-28 08:45")

#Since this is an example we must convert the character dates to POSIXct
Dates<-as.POSIXct(Dates, format="%Y-%m-%d %H:%M")

#Example Data
Data<-c(1,2,3)

#Creat Df
DF<-data.frame(Dates,Data)

#We can see we are missing  a 15 min interval at 8:30
>DF
                Dates Data
1 2012-09-28 08:00:00    1
2 2012-09-28 08:15:00    2
3 2012-09-28 08:45:00    3

#Pad on interval= 15 min
PaddedDF<-pad(DF, interval='15 min')

>PaddedDF
                Dates Data
1 2012-09-28 08:00:00    1
2 2012-09-28 08:15:00    2
3 2012-09-28 08:30:00   NA
4 2012-09-28 08:45:00    3
23 questions
0
votes
2 answers

Having issues using Pad function to fill in date with time gaps

I am having issues using the Pad function (Padr) to fill in gaps within a time series. I have some code that downloads hourly data from a server, one day at a time for a specific time period. After each day of data has been downloaded the aim is to…
adamR
  • 25
  • 4
0
votes
1 answer

Padding around dates in R to add missing/blank months?

The padr R pacakge vignette describes different package functions to pad dates and times around said dates and times. I am in situations where I'll be tallying events in data frames (ie dplyr::count()) and will need to plot occurrences, over a…
Display name
  • 4,153
  • 5
  • 27
  • 75
0
votes
1 answer

padding for weeks outside of the dates in the original data

How can I pad for weeks outside of the dates in the original data? library(tidyverse) df <- data.frame(x=c("2019-01-02", "2019-01-02", #"2019-01-03", "2019-01-04", …
Eric Green
  • 7,385
  • 11
  • 56
  • 102
0
votes
1 answer

How can I use PAD function (from PADR() package) for multiple data frames?

I have 24 files (1 for each hour of the day, HR_NBR = Hour Number) and I've to pad the dates in each of the files. AS-IS data: CLNDR_DT HR_NBR QTY 01/07/2016 1 6 03/07/2016 1 10 TO-BE data: CLNDR_DT HR_NBR QTY 01/07/2016 1 …
S Ne.
  • 3
  • 2
0
votes
1 answer

R, padr adding missing rows based on column content

I am using padr for the date padding for a data-frame. It added the rows but how can I have them added smartly? It’s wanted to sort the data-frame by staff and date_time then to add the missing rows in-between for a staff. (the missing between 2…
Mark K
  • 8,767
  • 14
  • 58
  • 118
0
votes
1 answer

Inserting Row in Missing Hourly Data in R using padr package - weird error

I am new to R and I am having some issues with the padr package described here. I have a hourly data set that is missing hours and I would like to insert a row to input a value for the missing data. I am trying to use the pad function and the…
mcat
  • 75
  • 5
0
votes
1 answer

Passing unquoted column list to fill_by_function in padr

I used padding (from padr package) on a data frame to fill the time gap. Now, to fill the gap values for a specified set of columns, I am using fill_by_function. In general, fill_by_function takes the unquoted column names as arguments. However, in…
user2129946
  • 59
  • 1
  • 4
-1
votes
1 answer

Add rows with specific value and replace missing values with zero in R

This is my data frame: year year_month month distance weeksum 1 2017 2017_05 05 15 4 2 2017 2017_05 05 10 1 3 2017 2017_05 05 5 5 4 2017 …
1
2