# Step 1: Load necessary libraries
library(dplyr)
# Step 2: Create a sample data frame with a date column
data <- data.frame(
date = seq(as.Date("2023-01-01"), as.Date("2023-01-10"), by = "days"),
value = rnorm(10)
)
# Step 3: Convert the 'date' column to a Date object (if not already)
data$date <- as.Date(data$date)
# Step 4: Set the 'date' column as the index
data <- data %>%
mutate(date = as.Date(date)) %>%
arrange(date) %>%
rownames_to_column(var = "index") %>%
select(-index)
# Result: The 'date' column is now the index of the data frame
print(data)