Mr Copper
2011-May-10 06:26 UTC
[R] Scale time series in a way that 90% of the data is in the -0.-9/ +0.9 range
Hello, please excuse my ignorance as i am new to R and this might seem trivial to you How can i scale my time series in a way that 90% of the data is in the -0.-9/ +0.9 range? I think i first have to select the 90% closest to the mean and then calculate my scaling parameter on it, then scale the whole series. I think i could use outlier() from outliers package to identify the outer 10%, extract them and then do my scaling, but i assume there is a more elegant /efficient way to do so. Does anyone have a hint for me? Thanks in advance, Warren [[alternative HTML version deleted]]
Mr.Q
2011-May-12 13:40 UTC
[R] Scale time series in a way that 90% of the data is in the -0.-9/ +0.9 range
Hello,
How can i scale my time series in a way that 90% of the data is in the
-0.-9/ +0.9 range?
My approach is to first build a clean vector without those 10% far
away from the mean
require(outliers)
y<-rep(c(1,1,1,1,1,9),10)
yc<-y
ycc<-length(y)*0.1
for(j in 1:ycc)
{
cat("Remove",j)
yc<-rm.outlier(yc)
}
and then do my scaling based on the cleaned data
for(k in 1:length(y)) {
y[k]<-(((y[k]-min(yc))/(max(yc)-min(yc)))*1.8)-0.9
}
This works fine for the first three loops, but then strangely crashes :
(
Remove 1Remove 2Remove 3Error in if (xor(((max(x, na.rm = TRUE) -
mean(x, na.rm = TRUE)) < (mean(x, :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In max(x, na.rm = TRUE) :
no non-missing arguments to max; returning -Inf
2: In min(x, na.rm = TRUE) :
no non-missing arguments to min; returning Inf
Any ideas for me?
Thanks in advance,
Mr. Q