forked from USGS-R/sensorQC
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jordan S Read
committed
Oct 22, 2015
1 parent
599b871
commit 755f164
Showing
7 changed files
with
143 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#' clean a sensor or a flagged sensor | ||
#' | ||
#' clean a sensor or a flagged sensor | ||
#' | ||
#' @param x sensor object | ||
#' @param which flags to replace | ||
#' @param \dots additional flags to use (passed to flag(x,...)) | ||
#' @param replace replacement value for flagged indices. | ||
#' NULL removes the flagged row | ||
#' @rdname clean | ||
#' | ||
#' @examples | ||
#' data = c(999999, 1,2,3,4,2,3,4) | ||
#' sensor = flag(data, 'x > 9999') | ||
#' clean(sensor) | ||
#' clean(data, 'x > 9999', 'persist(x) > 10', 'MAD(x) > 3', replace=NA) | ||
#' @export | ||
clean = function(x, which, ..., replace){ | ||
UseMethod('clean') | ||
} | ||
|
||
#' @export | ||
clean.numeric <- function(x, which = 'all', ..., replace=NULL){ | ||
x = sensor(x) | ||
clean(x, which = which, ..., replace=replace) | ||
} | ||
|
||
#' @export | ||
clean.sensor <- function(x, which = 'all', ..., replace=NULL){ | ||
|
||
if (which == 'all'){ | ||
if (!is.null(x$flags)){ | ||
flag.i = sort(unique(unlist(sapply(flags(x), function(x) x$flag.i)))) | ||
x$flags <- NULL | ||
} else { | ||
return(x) | ||
} | ||
|
||
if (is.null(replace)){ | ||
x$sensor <- x$sensor[c(-flag.i),] | ||
rownames(x$sensor) <- seq_len(nrow(x$sensor)) | ||
} else { | ||
x$sensor$x[flag.i] <- replace | ||
} | ||
return(x) | ||
} else { | ||
x <- flag(x, flag.defs=which, ...) | ||
clean(x, which = 'all', replace=replace) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
% Generated by roxygen2 (4.1.1): do not edit by hand | ||
% Please edit documentation in R/clean.R | ||
\name{clean} | ||
\alias{clean} | ||
\title{clean a sensor or a flagged sensor} | ||
\usage{ | ||
clean(x, which, ..., replace) | ||
} | ||
\arguments{ | ||
\item{x}{sensor object} | ||
|
||
\item{which}{flags to replace} | ||
|
||
\item{replace}{replacement value for flagged indices. | ||
NULL removes the flagged row} | ||
|
||
\item{\dots}{additional flags to use (passed to flag(x,...))} | ||
} | ||
\description{ | ||
clean a sensor or a flagged sensor | ||
} | ||
\examples{ | ||
data = c(999999, 1,2,3,4,2,3,4) | ||
sensor = flag(data, 'x > 9999') | ||
clean(sensor) | ||
clean(data, 'x > 9999', 'persist(x) > 10', 'MAD(x) > 3', replace=NA) | ||
} | ||
|