# Load required libraries
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(lubridate)
library(tidyquant)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## ── Attaching core tidyquant packages ──────────────────────── tidyquant 1.0.9 ──
## ✔ PerformanceAnalytics 2.0.4 ✔ TTR 0.24.4
## ✔ quantmod 0.4.26 ✔ xts 0.14.0── Conflicts ────────────────────────────────────────── tidyquant_conflicts() ──
## ✖ zoo::as.Date() masks base::as.Date()
## ✖ zoo::as.Date.numeric() masks base::as.Date.numeric()
## ✖ dplyr::filter() masks stats::filter()
## ✖ xts::first() masks dplyr::first()
## ✖ dplyr::lag() masks stats::lag()
## ✖ xts::last() masks dplyr::last()
## ✖ PerformanceAnalytics::legend() masks graphics::legend()
## ✖ quantmod::summary() masks base::summary()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(readxl)
library(writexl)
# Step 2: Import the data file 'bikes.xlsx' from the Desktop
# Replace 'your_username' with your actual system username
bikes_data <- read_excel("/cloud/project/bikes.xlsx") # For Windows
# bikes_data <- read_excel("/Users/your_username/Desktop/bikes.xlsx") # For Mac
# Step 3: Show "model" and "price" column with "price" in descending order
bikes_price_desc <- bikes_data %>%
select(model, price) %>%
arrange(desc(price))
# View the result
print(bikes_price_desc)
## # A tibble: 97 × 2
## model price
## <chr> <dbl>
## 1 Supersix Evo Black Inc. 12790
## 2 Scalpel-Si Black Inc. 12790
## 3 Habit Hi-Mod Black Inc. 12250
## 4 F-Si Black Inc. 11190
## 5 Supersix Evo Hi-Mod Team 10660
## 6 Synapse Hi-Mod Disc Black Inc. 9590
## 7 Scalpel-Si Race 9060
## 8 F-Si Hi-Mod Team 9060
## 9 Trigger Carbon 1 8200
## 10 Supersix Evo Hi-Mod Dura Ace 1 7990
## # ℹ 87 more rows
# Step 4: Show "model" and "price" column where "price" is greater than the mean value of price
mean_price <- mean(bikes_data$price, na.rm = TRUE)
bikes_price_above_mean <- bikes_data %>%
select(model, price) %>%
filter(price > mean_price)
# View the result
print(bikes_price_above_mean)
## # A tibble: 35 × 2
## model price
## <chr> <dbl>
## 1 Supersix Evo Black Inc. 12790
## 2 Supersix Evo Hi-Mod Team 10660
## 3 Supersix Evo Hi-Mod Dura Ace 1 7990
## 4 Supersix Evo Hi-Mod Dura Ace 2 5330
## 5 Supersix Evo Hi-Mod Utegra 4260
## 6 CAAD12 Black Inc 5860
## 7 CAAD12 Disc Dura Ace 4260
## 8 Synapse Hi-Mod Disc Black Inc. 9590
## 9 Synapse Hi-Mod Disc Red 7460
## 10 Synapse Hi-Mod Dura Ace 5860
## # ℹ 25 more rows