Load required libraries

library(dplyr)
library(tidyr)
library(xts)

Read the dataset

df_raw <- read.csv("Part1.csv", stringsAsFactors = FALSE)

Reshape and format the columns

data_wide <- df_raw %>%
  select(Date, COID, Close) %>%
  mutate(COID = sprintf("%04d", as.numeric(COID))) %>%
  pivot_wider(names_from = COID, values_from = Close) %>%
  rename(
    `0050 元大台灣50` = `0050`,
    `0052 富邦科技`   = `0052`,
    `0056 元大高股息` = `0056`
  ) %>%
  mutate(mdate = as.Date(Date, format = "%m/%d/%Y")) %>%
  select(mdate, `0050 元大台灣50`, `0052 富邦科技`, `0056 元大高股息`) %>%
  arrange(mdate)

Output

etf_ts <- xts(data_wide[, -1], order.by = data_wide$mdate)
head(etf_ts)
##            0050 元大台灣50 0052 富邦科技 0056 元大高股息
## 2010-01-04          8.4501        2.9216          8.4679
## 2010-01-05          8.4501        2.9256          8.4318
## 2010-01-06          8.6072        2.9936          8.5579
## 2010-01-07          8.5847        2.9616          8.4859
## 2010-01-08          8.6371        2.9528          8.5760
## 2010-01-11          8.6595        2.9696          8.6660