fortify_df: Create a fortified dataframe.

Description Usage Arguments Value Author(s) Examples

View source: R/basicUtils.R

Description

Takes a dataframe with silent lost values and makes it explicit with NAs with the help of a security interval defined by fInterval.

Usage

1
fortify_df(df, fInterval, by, names)

Arguments

df

a list of dataframes with a dates column in POSIXct format an another column with any value type. It can be a single dataframe with multiple columns too.

fInterval

a 2-item vector with 'start' and 'end' POSIXct dates respectively. All and only all the values in the given interval will be explicitdly included in the resulting dataframe, with NAs in case of missing observations in the input dataframe. By default the limit dates are extracted from the data, in this case 'start' and end' its the minimun and maximun dates for all the dataframes given in dfList.

by

a character string, containing the data increment in terms of "sec", "min", "hour", "day", "DSTday", "week", "month", "quarter" or "year". This can optionally be preceded by a (positive or negative) integer and a space, or followed by "s". See seq.POSIXt for more info. The increment provided must equivalent to the real data-time increment.

names

a vector of names for the dataframe values. If a character vector are not provided the columns will be renamed with capital letters.

Value

A fortified dataframe, i.e with all the lost values explicited. The resulting time index its perfectly defined by seq(start,end,by), so the columns of the dataframe created with this function will have the same index, i.e the silent lost values of the inputs dataframes (the columns in the new one) will be marked with NAs in the right positions.

Author(s)

JV Yago

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#One column dataframe with silent lost observations
start <- as.POSIXct("2019/01/01")
end   <- as.POSIXct("2019/01/02")
dates <- seq(start, end, by = "hour")
df.simple <- data.frame(dates = dates[-(sample(1:25,5))], values=rep(1,20))
fortify_df(df=df.simple, by="hour")

#Multiple column dataframe with silent lost observations
df.complex <- data.frame(dates = dates[-(sample(1:25,5))],
                         A = 1:20, B = LETTERS[1:20],
                         C = rnorm(1:20))
fortify_df(df=df.complex, by="hour")

# Multiple datafrems with silent lost observations
df.A <- data.frame(dates = dates[-(sample(1:25,5))], a = 1:20)
df.B <- data.frame(dates = dates[-(sample(1:25,3))], a = 1:22)
df.C <- data.frame(dates = dates[-(sample(1:25,7))], a = 1:18)
fortify_df(list(df.A, df.B, df.C), by = "hour")

VicenteYago/sensorsUtils documentation built on Jan. 29, 2022, 12:44 a.m.