LoslegenKostenlos loslegen

Saving time - I

You've now successfully converted your flights data into an xts object, plotted information over time, and calculated a few valuable metrics to help you proceed with analysis. You've even been able to conduct some quick descriptive analysis on your data by plotting these metrics over time.

The final step in any time series data manipulation is to save your xts object so you can easily return to it in the future.

As a first step, you'll want to save your xts object as a rds file for your own use. To do this, you'll use the command saveRDS(), which saves your object to a file with the name you specify (using the file argument). By default, saveRDS() will save to the current working directory.

When you're ready to return your saved data, you can use the readRDS() command to reopen the file. As you'll see in this exercise, this method maintains the class of your xts object.

Diese Übung ist Teil des Kurses

Case Study: Analyzing City Time Series Data in R

Kurs anzeigen

Anleitung zur Übung

  • Use saveRDS() to save your flights_xts data object to a rds file. Call this file "flights_xts.rds".
  • Open your rds file using readRDS(). Save your new data as flights_xts2.
  • Use class() to check the class of your new flights_xts2 object.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Save your xts object to rds file using saveRDS
saveRDS(object = ___, file = "___")

# Read your flights_xts data from the rds file
flights_xts2 <- readRDS("___")

# Check the class of your new flights_xts2 object


# Examine the first five rows of your new flights_xts2 object
Code bearbeiten und ausführen