michael
michael

Reputation: 11

zoo Warning: number of items to replace is not a multiple of replacement length

I'm a new user of zoo and trying to get the min of two elements in a zoo object, and assign it to one of them. I've got the following error message. Please help shed some lights.

library("tseries")
IBM <- get.hist.quote(instrument="IBM", start="2012-01-01", end="2012-12-31")
IBM[1]$Low <- min( IBM[1]$Low , IBM[2]$Low )
Warning message:
In NextMethod("[<-") :
  number of items to replace is not a multiple of replacement length

Upvotes: 1

Views: 1818

Answers (1)

Joshua Ulrich
Joshua Ulrich

Reputation: 176688

That's a warning, not an error; and it's caused by the peculiar way you're subsetting. I've never seen someone subset by row first, then column use the $ function. I would advise you to use $ to subset by column first, then by row.

This works without a warning:

IBM$Low[1] <- min(IBM$Low[1:2])

Upvotes: 2

Related Questions