dr_replace() includes two approaches for identifying problematic observations for specific measurements that should be recoded as missing values (NA).

dr_replace(.data, sourceVar, cleanVar = NULL, overwrite = FALSE, dateVar = NULL,
    timeVar = NULL, from = NULL, to = NULL, tz = NULL, exp)

Arguments

.data

A tbl

sourceVar

Name of variable to replace missing values in

cleanVar

New variable name for cleaned data

overwrite

A logical scalar. Should the current variable be overwritten instead of creating a new variable?

dateVar

Name of variable containing date data

timeVar

Name of variable containing time data

from

Beginning date and (optionally) time to remove observations

to

End date and (optionally) time to remove observations

tz

String name of timezone, defaults to system's timezone

exp

Unquoted expression

Value

An object of the same class as .data with specified observations recoded as missing.

Details

During monitoring, a sensor malfunction may impact only a single element of a given reading. Removing the entire observation may therefore be imprudent. dr_replace() provides two methods for identifying these values and declaring them as missing. Values can be identified by specifying one or two timepoints in the data where problematic measurements begin, end, or fall between. Values can also be identified based on a problematic sensor value or range of values using an expression.

Examples

testData <- data.frame( Date = c("9/18/2015", "9/18/2015", "9/18/2015", "9/18/2015", "9/19/2015", "9/21/2015"), Time = c("12:10:49", "12:15:50", "12:20:51", "12:25:51", "12:30:51", "12:35:51"), Temp = c(14.76, 14.64, 14.57, 14.51, 14.50, 14.63), SpCond = c(0.754, 0.750, 0.750, 0.749, 0.749, 0.749), stringsAsFactors = FALSE ) dr_replace(testData, sourceVar = Temp, dateVar = Date, timeVar = Time, from = "2015-09-19 12:30:51", to = "2015-09-21 12:35:51")
#> Replacement approach - completed using the date/time arguments.
#> Date Time Temp SpCond Temp_na #> 1 9/18/2015 12:10:49 14.76 0.754 14.76 #> 2 9/18/2015 12:15:50 14.64 0.750 14.64 #> 3 9/18/2015 12:20:51 14.57 0.750 14.57 #> 4 9/18/2015 12:25:51 14.51 0.749 14.51 #> 5 9/19/2015 12:30:51 14.50 0.749 NA #> 6 9/21/2015 12:35:51 14.63 0.749 14.63
dr_replace(testData, sourceVar = Temp, dateVar = Date, timeVar = Time, from = "2015-09-19", to = "2015-09-21")
#> Replacement approach - completed using the date/time arguments.
#> Date Time Temp SpCond Temp_na #> 1 9/18/2015 12:10:49 14.76 0.754 14.76 #> 2 9/18/2015 12:15:50 14.64 0.750 14.64 #> 3 9/18/2015 12:20:51 14.57 0.750 14.57 #> 4 9/18/2015 12:25:51 14.51 0.749 14.51 #> 5 9/19/2015 12:30:51 14.50 0.749 NA #> 6 9/21/2015 12:35:51 14.63 0.749 14.63
dr_replace(testData, sourceVar = Temp, dateVar = Date, timeVar = Time, from = "2015-09-19")
#> Replacement approach - completed using the date/time arguments.
#> Date Time Temp SpCond Temp_na #> 1 9/18/2015 12:10:49 14.76 0.754 14.76 #> 2 9/18/2015 12:15:50 14.64 0.750 14.64 #> 3 9/18/2015 12:20:51 14.57 0.750 14.57 #> 4 9/18/2015 12:25:51 14.51 0.749 14.51 #> 5 9/19/2015 12:30:51 14.50 0.749 NA #> 6 9/21/2015 12:35:51 14.63 0.749 NA
dr_replace(testData, sourceVar = Temp, dateVar = Date, timeVar = Time, to = "2015-09-19")
#> Replacement approach - completed using the date/time arguments.
#> Date Time Temp SpCond Temp_na #> 1 9/18/2015 12:10:49 14.76 0.754 NA #> 2 9/18/2015 12:15:50 14.64 0.750 NA #> 3 9/18/2015 12:20:51 14.57 0.750 NA #> 4 9/18/2015 12:25:51 14.51 0.749 NA #> 5 9/19/2015 12:30:51 14.50 0.749 14.50 #> 6 9/21/2015 12:35:51 14.63 0.749 14.63
dr_replace(testData, sourceVar = Temp, cleanVar = temp2, dateVar = Date, timeVar = Time, to = "09/19/2015 12:35:51")
#> Replacement approach - completed using the date/time arguments.
#> Date Time Temp SpCond temp2 #> 1 9/18/2015 12:10:49 14.76 0.754 NA #> 2 9/18/2015 12:15:50 14.64 0.750 NA #> 3 9/18/2015 12:20:51 14.57 0.750 NA #> 4 9/18/2015 12:25:51 14.51 0.749 NA #> 5 9/19/2015 12:30:51 14.50 0.749 NA #> 6 9/21/2015 12:35:51 14.63 0.749 14.63
dr_replace(testData, sourceVar = Temp, overwrite = TRUE, exp = Temp > 14.75)
#> Replacement approach - completed using the expression.
#> Date Time Temp SpCond #> 1 9/18/2015 12:10:49 NA 0.754 #> 2 9/18/2015 12:15:50 14.64 0.750 #> 3 9/18/2015 12:20:51 14.57 0.750 #> 4 9/18/2015 12:25:51 14.51 0.749 #> 5 9/19/2015 12:30:51 14.50 0.749 #> 6 9/21/2015 12:35:51 14.63 0.749