Skip to content

Delete bad dividend row

3 messages · Frank, G See

#
Hi all,

I successfully get dividend data from Yahoo Finance, including a bad
dividend:

2012-12-20 0.039

How do I delete this one row from the data? This dividend shows up on the
Yahoo Finance site but is not reported by Philip Morris. 

Thanks,

Frank
Chicago, IL


R version 3.0.1 (2013-05-16) -- "Good Sport"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

? Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]
Loading required package: Defaults
Loading required package: xts
Loading required package: zoo

Attaching package: 'zoo'

The following object is masked from 'package:base':

??? as.Date, as.Date.numeric

Loading required package: TTR
Version 0.4-0 included new data defaults. See ?getSymbols.
??????????? [,1]
2010-03-23 0.580
2010-06-22 0.580
2010-09-22 0.640
2010-12-21 0.640
2011-03-22 0.640
2011-06-21 0.640
2011-09-23 0.770
2011-12-20 0.770
2012-03-27 0.770
2012-06-25 0.770
2012-09-25 0.850
2012-12-20 0.039
2012-12-24 0.850
2013-03-26 0.850
2013-06-25 0.850
?? user? system elapsed 
?? 0.92??? 0.04??? 1.04
#
Hi Frank,

There are a few ways to do it.

library(quantmod)
div <- getDividends("PM", from="2010-01-01")

# find the row(s) you want to remove and use negative indexing
div[-12]
div[-which(div == 0.039)]
div[-div["2012-12-20", which.i=TRUE]]

# exclude specific date by passing logical vector to [.xts
div[!index(div) %in% as.Date("2012-12-20")]

# exclude specific weekdays
div[weekdays(index(div)) != "Thursday"]
div[as.POSIXlt(index(div))$wday != 4]

# exclude amounts smaller than some arbitrary number
div[div > 0.1]
# exclude specific amount
div[div != 0.039]

HTH,
Garrett
#
Hi Garret,

That did help. I've been analyzing dividend yields and the quantmod
getDividends and getSymbols work flawlessly. But then the dividends change
frequency over time, special dividends creep in and now a spurious data
point for PM. So far I've dealt with these with your help and others. 

Best,

Frank

-----Original Message-----
From: G See [mailto:gsee000 at gmail.com] 
Sent: Sunday, June 30, 2013 5:15 PM
To: Frank
Cc: r-sig-finance
Subject: Re: [R-SIG-Finance] Delete bad dividend row

Hi Frank,

There are a few ways to do it.

library(quantmod)
div <- getDividends("PM", from="2010-01-01")

# find the row(s) you want to remove and use negative indexing
div[-12]
div[-which(div == 0.039)]
div[-div["2012-12-20", which.i=TRUE]]

# exclude specific date by passing logical vector to [.xts
div[!index(div) %in% as.Date("2012-12-20")]

# exclude specific weekdays
div[weekdays(index(div)) != "Thursday"]
div[as.POSIXlt(index(div))$wday != 4]

# exclude amounts smaller than some arbitrary number
div[div > 0.1]
# exclude specific amount
div[div != 0.039]

HTH,
Garrett