0

I want to transform my excel (bank return & the date) in a zoo object, with the data in the zoo object being numeric & date. I used the following data:

Classes ‘tbl_df’, ‘tbl’ and 'data.frame':   1455 obs. of  2 variables:
 $ date         : POSIXct, format: "1925-01-02" "1925-01-03" "1925-01-05" "1925-01-06" ...
 $ Deutsche Bank: num  0.181 0.191 0.191 0.184 0.186 ...

I used the following code:

db.xts <- na.omit(as.data.frame(db.kurs))

db.xts2 <- db.xts %>% mutate(date = as.Date(date, format = "%d.%m.%Y")) %>% mutate(`Deutsche Bank` = as.numeric(`Deutsche Bank`))

db.xts3 <- as.xts(db.xts2, db.kurs$date)
db.zoo <- as.zoo(db.xts3)
db.zoo <- db.zoo[, colnames(db.zoo) != "date"]

which leaves me with the following:

‘zoo’ series from 1925-01-02 to 1929-12-31
  Data: chr [1:1455] "0.1807194" "0.1911455" "0.1911455" "0.1841948" "0.1859325" "0.1841948" "0.1807194" "0.1789817" ...
  Index:  POSIXct[1:1455], format: "1925-01-02" "1925-01-03" "1925-01-05" "1925-01-06" "1925-01-07" "1925-01-08" "1925-01-09" "1925-01-10" ...

If I try to run it without the as.xts command R deletes all the dates and uses an iteger from 1 to 1455. Does anybody have an idea how to solve it?

Thanks for the help,

Nick

M--
  • 25,431
  • 8
  • 61
  • 93
N.Messers
  • 60
  • 1
  • 8
  • Which of the 2 `as.xts()` commands in your code are you referring to? There also appears to be a lot of extraneous code. It would help others help you if you provided a minimal [reproducible example](https://stackoverflow.com/q/5963269). – Joshua Ulrich Mar 30 '18 at 18:46
  • Hey, is it better this way? I tried to not hold back any information that could be useful. – N.Messers Apr 04 '18 at 08:24

0 Answers0