data(AirPassengers) # already in your R installation, via package "datasets" AP = AirPassengers class(AP) # returns "ts" AP1 = as.numeric(AP) # returns "numeric" # another way to do it AP1 = unclass(AP)
AP1 is a vector with the same values and length as AP. The class is now numeric, not ts, which means, in particular, that indexes are no longer a kind of date object, but simply ordinary consecutive integers.
So w / r / t is a specific question in OP, either of the two snippets above will "convert [ts object] to a plain old vector"
If you need to do the same with indexes, and not, or in addition to values, that is, from Date objects to numeric, you can do it like this:
fnx = function(num_days_since_origin, origin="1970-01-01") { as.Date(num_days_since_origin, origin="1970-01-01") } a = as.Date("1985-06-11") a2 = as.numeric(a)
doug
source share