0

I am working on a "data.frame" object and trying to convert it to "ts" object. Below is the sample data:

 date   sales
 5/1/2015   200
 5/1/2015   189.83
 6/1/2015   500
 7/1/2015   400
 8/1/2015   345
 9/1/2015   2948.87
 10/1/2015  3847.39
 10/1/2015  473.45

10/1/2015 is not max date there is much more data.

Below is the Rcode:

f <- data.frame(fs$date, fs$sales )

colnames(f) <- c("date","sales")
head(f, n=5)
class(f) 

flt <- ts(f$sales, start = c(2015,1),freq = 12)
head(flt, n = 10)
str(flt)

For the str I am not getting the 2015 to 6694 correctly.

Time-Series [1:56150] from 2015 to 6694: 200 189.83 500 400 354 ...

How to set to correct time frame with correct sales amount? Thanks in advance!

sharp
  • 2,140
  • 9
  • 43
  • 80
  • Can you`dput(fs)` and post the output in your question so we can [reproduce](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) your example please. – Badger Oct 16 '15 at 19:13
  • Data is way too large, that why I posted sample few rows. I also cannot share the original data set. – sharp Oct 16 '15 at 19:32
  • Just curious, but do you need to convert it to "ts" for some operation? I've had some frustration in the past with "ts" for certain things like this. – giraffehere Oct 16 '15 at 19:34
  • `dput(fs[1:10,])` so we have something to play with at least. – Badger Oct 16 '15 at 19:37
  • 1
    The first two dates in your input are the same and the last two dates in your input are the same so it is not a time series. Also as others have pointed out the code in the question is not reproducible so it's impossible to really know what you have. See: http://stackoverflow.com/help/mcve and http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – G. Grothendieck Oct 16 '15 at 20:10
  • @G.Grothendieck, I missed that, excellent point! You would need to add up each day, giving a single data point per day to generate a true time series. Maybe that will help. – Badger Oct 16 '15 at 21:06
  • I am planning on using linear regression or time series to predict the future sales values. I'll have use "ts" time series object. There are many dates that are similar, do I need to combine these or order them in chronological order? Please see the dput output: – sharp Oct 19 '15 at 19:41
  • structure(list(date = c(20150401L, 20150401L, 20150401L, 20150401L, 20150501L, 20150501L, 20150401L, 20150501L, 20150601L, 20150601L ), sales = c(940, 212, 969.4, 484.7, 700, 940, 20540, 15326, 969.4, 290)), .Names = c("date", "sales"), row.names = c(NA, 10L), class = "data.frame") – sharp Oct 19 '15 at 19:41

0 Answers0