[R-SIG-Finance] removing repeating values from xts series
patrick at burns-stat.com
Wed Sep 15 09:33:20 CEST 2010
So you want to compare
I think. And save the rows
that aren't all equal. Yes?
On 15/09/2010 08:25, Ulrich Staudinger wrote:
> Hi David,
> as far as I understand, duplicated works from the inner workings very
> much like unique.
> With a vector y (in this case no timeseries), duplicated yields:
>  1 1 2 3 2 2 2 2 1
>  FALSE TRUE FALSE FALSE TRUE TRUE TRUE TRUE TRUE
> But what I would like to have is:
> FALSE TRUE FALSE FALSE FALSE TRUE TRUE TRUE FALSE
> or ...
> 1 2 3 2 1
> I am not so sure that duplicated is what I want, unless I didn't spot
> something ... some other approach maybe?
> On Wed, Sep 15, 2010 at 9:08 AM, Lüthi David (XICD 1)
> <david.luethi at claridenleu.com> wrote:
>> try duplicated(xts.object, ...) or possibly duplicated(as.data.frame(xts.object), ...) if all columns should be considered.
>> Regards, david
>> -----Original Message-----
>> From: r-sig-finance-bounces at stat.math.ethz.ch [mailto:r-sig-finance-bounces at stat.math.ethz.ch] On Behalf Of Ulrich Staudinger
>> Sent: Wednesday, September 15, 2010 8:28 AM
>> To: r-sig-finance
>> Subject: [R-SIG-Finance] removing repeating values from xts series
>> Hi fellows,
>> I am facing a case that I cannot solve with my limited knowledge of R,
>> unless I write the function myself - which I would like to avoid
>> (reusing is better than reinventing the wheel). Following the relevant
>> Input scenario:
>> An xts time series object with duplicates, the object contains bid,
>> bid volume, ask, ask volume.
>> 01-01-2010 09:00:01 100 1 101 1
>> 01-01-2010 09:00:02 100 1 101 1
>> 01-01-2010 09:00:03 100 1 101 1
>> 01-01-2010 09:00:04 101 1 102 1
>> 01-01-2010 09:00:05 102 1 102 1
>> 01-01-2010 09:00:06 100 1 101 1
>> A timeseries with only non-repeating values, removing the duplicates
>> in between the values.
>> I tried "unique" already, but that one returns only the unique values
>> from within the whole timeseries and not on a running base.
>> Example code:
>> The following example code exemplifies with a non-xts series what I
>> want to achieve ...
>>> y = c(1,1,2,2,1,1,1,2,3,4,3,3,3,3,3,1)
>>> removeDuplicates<- function(input)
>> index = 2
>> ret = c(input)
>> for(i in 2:length(input))
>> ret[index] = input[i]
>> index = index + 1
>>  1 2 1 2 3 4 3 1
>> How can I make this with an xts series? Is there a function for this?
>> Thanks in advance,
>> with kind regards,
>> Ulrich Staudinger
>> R-SIG-Finance at stat.math.ethz.ch mailing list
>> -- Subscriber-posting only. If you want to post, subscribe first.
>> -- Also note that this is not the r-help list where general R questions should go.
patrick at burns-stat.com
More information about the R-SIG-Finance