Prepping and importing time series data (for noobs)

Hey :slightly_smiling_face: no one is being dense here, and we're communicating, so all misunderstandings, if any, are on me at least as much as they are on you. It's simply that not in person discussions about code require some more iterations. That's why it's useful to turn questions into a self-contained reprex (short for repr oducible ex ample). This will ensure we're all looking at the same data and code. A guide for creating a reprex can be found here.

I didn't suggest you to use a reprex initially, because when you start learning about reprexes, one of the less intuitive things to learn (IMO) is how to write a reprex when the problem is due to a very large data file which you can't just copy & paste here. Since you didn't try to copy & paste your dataset (which is the first thing beginners usually try to do), I incorrectly assumed that it was large, and I didn't want to put too much on your plate by asking you to mock complex data. Anyway, here's a guide to preparing your data for use in a reprex. Go through it at your own pace, and you will build up a fundamental skill for a career as a developer or data scientist - minimizing the time spent by you (and the people helping you) in getting help on you code, without sacrificing clarity.

Coming back to your actual question :slight_smile: nothing is wrong with your data, or with your description of the data. Forget about what I wrote before - everything is much more clear now that I saw a subset of your data. And you did a very fine job of showing it to me! I was going to ask you to upload a screenshot (which you can do with the upload icon, the one to right of the </>), which isn't definitely a best practice! but it's easier for beginners. However you did better than that, and used str(eurdata), which means that you already imported the data in R! You're good! str is a very useful command: I also suggest learning about dplyr::glimpse.

Well, you have your data in R: cool. Now, you say that the time series tools you're using don't like this data format: I have half an idea about what's happening, but since I'm not good at mind reading, this is really the time for writing a reprex, including all the steps you're doing, and the errors you're getting, which prevent you from going forward. Go forth, and read the reprex FAQ I linked to - I'm sure you'll make a great reprex. Just one suggestion - your data frame is so small that you could even simply copy & paste it in your reprex, but since we're learning here, let's go straight to better practices. Here's one:

# select only the first 50 rows of your data frame, and ALL columns that you need for your reprex
eurdata_small <- eurdata[1:50, ]
dput(eurdata_small)

Now, the command dput(eurdata_small) will return a very weird output to the console - something like (but not identical to)

structure(list(date = list(structure(-61289950328, class = c("POSIXct", 
"POSIXt"), tzone = ""), structure(-61258327928, class = c("POSIXct", 
"POSIXt"), tzone = "")), id = c("0001234", "0001235"), ammount = c("$18.50", 
"-$18.50")), class = "data.frame", .Names = c("date", "id", "ammount"
), row.names = c(NA, -2L))

Don't worry and copy it to the clipboard. Then, in your reprex, just after loading all necessary packages and setting all options you need to set, write

eurdata_small <- structure(...)

where in place of structure(...) you paste what you just copied to the clipoard. Then, in the rest of the reprex, use eurdata_small as your data set. Now godspeed! :wink:

PS in time, you'll learn to prepare the minimum amount of fake data for your reprex, without having to rely on a subset of your actual data, but your current dataset is so simple that you don't need to worry about that for now.

4 Likes