Unexpected output containing plus, minus, and letters produced by subtracting one column of numbers from another in R

43 views Asked by At

I have a data.frame containing a vector of numeric values (prcp_log).

  waterdate  PRCP prcp_log
  <date>     <dbl>    <dbl>
1 2007-10-01  0      0     
2 2007-10-02  0.02   0.0198
3 2007-10-03  0.31   0.270 
4 2007-10-04  1.8    1.03  
5 2007-10-05  0.03   0.0296
6 2007-10-06  0.19   0.174

I then pass this data through Christiano-Fitzgerald band pass filter using the following command from the mfilter package.

library(mFilter)

US1ORLA0076_cffilter  <- cffilter(US1ORLA0076$prcp_log,pl=180,pu=365,root=FALSE,drift=FALSE,
                                  type=c("asymmetric"),
                                  nfix=NULL,theta=1)

Which creates an S3 object containing, among other things, and vector of "trend" values and a vector of "cycle" values, like so:

head(US1ORLA0076_cffilter$trend)
           [,1]
[1,] 0.05439408
[2,] 0.07275321
[3,] 0.32150292
[4,] 1.07958965
[5,] 0.07799329
[6,] 0.22082246

head(US1ORLA0076_cffilter$cycle)
            [,1]
[1,] -0.05439408
[2,] -0.05295058
[3,] -0.05147578
[4,] -0.04997023
[5,] -0.04843449
[6,] -0.04686915

Plotted:

plot(US1ORLA0076_cffilter)

enter image description here

I then apply the following mathematical operation in attempt to remove the trend and seasonal components from the original numeric vector:

US1ORLA0076$decomp <- ((US1ORLA0076$prcp_log - US1ORLA0076_cffilter$trend) - US1ORLA0076_cffilter$cycle)

Which creates an output of values which includes unexpected elements such as dashes and letters.

head(US1ORLA0076$decomp)
              [,1]
[1,]  0.000000e+00
[2,]  0.000000e+00
[3,]  1.387779e-17
[4,] -2.775558e-17
[5,]  0.000000e+00
[6,]  6.938894e-18

What has happened here? What do these additional characters signify? How can perform this mathematical operation and achieve the desired output of simply $log_prcp minus both the $tend and $cycle values?

I am happy to provide any additional info that will help right away, just ask.

0

There are 0 answers