clip_data clips the input sensor dataframe according to the given start and stop time

clip_data(df, start_time, stop_time)

Arguments

df

dataframe. Input dataframe of the multi-channel signal. The first column is the timestamps in POSXlct format and the following columns are accelerometer values.

start_time

POSXlct format or character. Start time for clipping. If it is a character, it should be recognizable by as.POSXlct function.

stop_time

POSXlct format or character. Stop time for clipping. If it is a character, it should be recognizable by as.POSXlct function.

Value

dataframe. The same format as the input dataframe.

Details

This function accepts a dataframe of multi-channel signal, clips it according to the start_time and stop_time.

How is it used in MIMS-unit algorithm?

This function is a utility function that was used in various part in the algorithm whenever we need to clip a dataframe.

Examples

  default_ops = options()
  options(digits.secs=3)
  # Use the provided sample data
  df = sample_raw_accel_data

  # Check the start time and stop time of the dataset
  summary(df)
#>  HEADER_TIME_STAMP                      X               Y            
#>  Min.   :2016-01-15 11:00:00.00   Min.   :0.129   Min.   :-2.715000  
#>  1st Qu.:2016-01-15 11:00:01.50   1st Qu.:1.004   1st Qu.:-0.309000  
#>  Median :2016-01-15 11:00:03.00   Median :1.205   Median :-0.125000  
#>  Mean   :2016-01-15 11:00:03.00   Mean   :1.273   Mean   :-0.008275  
#>  3rd Qu.:2016-01-15 11:00:04.50   3rd Qu.:1.583   3rd Qu.: 0.011000  
#>  Max.   :2016-01-15 11:00:06.00   Max.   :2.652   Max.   : 2.871000  
#>        Z          
#>  Min.   :-1.7300  
#>  1st Qu.:-0.3490  
#>  Median :-0.1840  
#>  Mean   :-0.2462  
#>  3rd Qu.:-0.0740  
#>  Max.   : 1.1090  

  # Use timestamp string to clip 1 second data
  start_time = "2016-01-15 11:01:00"
  stop_time = "2016-01-15 11:01:01"
  output = clip_data(df, start_time, stop_time)
  summary(output)
#>  HEADER_TIME_STAMP       X             Y             Z      
#>  Min.   :NA        Min.   : NA   Min.   : NA   Min.   : NA  
#>  1st Qu.:NA        1st Qu.: NA   1st Qu.: NA   1st Qu.: NA  
#>  Median :NA        Median : NA   Median : NA   Median : NA  
#>  Mean   :NaN       Mean   :NaN   Mean   :NaN   Mean   :NaN  
#>  3rd Qu.:NA        3rd Qu.: NA   3rd Qu.: NA   3rd Qu.: NA  
#>  Max.   :NA        Max.   : NA   Max.   : NA   Max.   : NA  

  # Use POSIXct timestamp to clip data
  start_time = as.POSIXct("2016-01-15 11:01:00")
  stop_time = as.POSIXct("2016-01-15 11:01:01")
  output = clip_data(df, start_time, stop_time)
  summary(output)
#>  HEADER_TIME_STAMP       X             Y             Z      
#>  Min.   :NA        Min.   : NA   Min.   : NA   Min.   : NA  
#>  1st Qu.:NA        1st Qu.: NA   1st Qu.: NA   1st Qu.: NA  
#>  Median :NA        Median : NA   Median : NA   Median : NA  
#>  Mean   :NaN       Mean   :NaN   Mean   :NaN   Mean   :NaN  
#>  3rd Qu.:NA        3rd Qu.: NA   3rd Qu.: NA   3rd Qu.: NA  
#>  Max.   :NA        Max.   : NA   Max.   : NA   Max.   : NA  

  # If start and stop time is not in the range of the input data
  # return empty data.frame
  start_time = "2016-01-15 12:01:00"
  stop_time = "2016-01-15 12:01:01"
  output = clip_data(df, start_time, stop_time)
  output
#> [1] HEADER_TIME_STAMP X                 Y                 Z                
#> <0 rows> (or 0-length row.names)

  # Restore original options
  options(default_ops)