Remove duplicate rows from xts object

泪湿孤枕 提交于 2019-11-28 09:30:52

Should't it be index(mt.xts) rather than mt.xts$Index? The following seems to work.

# Sample data
library(xts)
x <- xts( 
  1:10, 
  rep( seq.Date( Sys.Date(), by="day", length=5 ), each=2 ) 
)

# Remove rows with a duplicated timestamp
y <- x[ ! duplicated( index(x) ),  ]

# Remove rows with a duplicated timestamp, but keep the latest one
z <- x[ ! duplicated( index(x), fromLast = TRUE ),  ]

In my case,

x <- x[! duplicated( index(x) ),]

did not work as intended, because the system somehow makes date-time unique in each row.

x <- x[! duplicated( coredata(x) ),]

This may work if the previous solution did not help.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!