# Cleaning & Analyzing Cryptocurrency Data Using the tidyverse in R

The video was published on Albert Rapp’s YouTube channel and explains how to import, manipulate, and visualize a cryptocurrency data set containing Bitcoin and Ethereum values over time.

Here’s the code:

```# install.packages("tidyverse")                   # Install tidyverse packages

my_path <- "D:/Dropbox/Jock/Data Sets/"           # Specify directory path

tib_cc <- read_csv(str_c(my_path,                 # Import CSV file
"ETH-BTC-USD.csv"))
tib_cc                                            # Print tibble

tib_cc %>%                                        # Class of data set
class()

tib_cc %>%                                        # Show entire data set
View()

identical(tib_cc\$Close, tib_cc\$`Adj Close`)       # Compare two columns

tib_cc_sub <- tib_cc %>%                          # Extract certain columns
select(Date, Close, Currency)
tib_cc_sub                                        # Print updated tibble

tib_cc_sub_date <- tib_cc_sub %>%                 # Convert character to date
mutate(Date = mdy(Date))
tib_cc_sub_date                                   # Print updated tibble

tib_cc_sub_date %>%                               # Create line plot
ggplot(aes(x = Date,
y = Close,
col = Currency)) +
geom_line()

tib_cc_sub_date_index <- tib_cc_sub_date %>%      # Calculate index
group_by(Currency) %>%
mutate(Close_index = Close / first(Close) * 100) %>%
ungroup()
tib_cc_sub_date_index                             # Print updated tibble

tib_cc_sub_date_index %>%                         # Draw indexed line plot
ggplot(aes(x = Date,
y = Close_index,
col = Currency)) +
geom_line()

tib_cc %>%                                        # Do all in one run
select(Date, Close, Currency) %>%
mutate(Date = mdy(Date)) %>%
group_by(Currency) %>%
mutate(Close_index = Close / first(Close) * 100) %>%
ungroup() %>%
ggplot(aes(x = Date,
y = Close_index,
col = Currency)) +
geom_line()```

Subscribe to the Statistics Globe Newsletter