data(cars)
median(cars[, 1])
## [1] 15
library(jsonlite)
url <- "https://min-api.cryptocompare.com/data/v2/histoday?fsym=BTC&tsym=USD&limit=100"
btc_data <- fromJSON(url)
btc_prices <- btc_data$Data$Data
max_close_price <- max(btc_prices$close)
max_close_price
## [1] 124723
Student Habits vs Academic Performance
df <- read.csv("student_lifestyle_dataset.csv")
# 1. What is the average number of study hours per day among students?
mean(df$Study_Hours_Per_Day, na.rm = TRUE)
## [1] 7.4758
median(df$Study_Hours_Per_Day, na.rm = TRUE)
## [1] 7.4
# 2. Do students who sleep more have higher GPAs on average?
# Create two groups: <8 hours sleep vs >=8 hours
df$sleep_group <- ifelse(df$Sleep_Hours_Per_Day >= 8, "8+ hours", "<8 hours")
# Compare group averages
tapply(df$GPA, df$sleep_group, mean, na.rm = TRUE)
## <8 hours 8+ hours
## 3.116544 3.115138
# 3. What is the relationship (correlation) between study hours and GPA?
cor(df$Study_Hours_Per_Day, df$GPA, use = "complete.obs")
## [1] 0.734468
# 4. Which daily activity takes the most time on average for students?
means <- c(
study = mean(df$Study_Hours_Per_Day, na.rm = TRUE),
sleep = mean(df$Sleep_Hours_Per_Day, na.rm = TRUE),
social = mean(df$Social_Hours_Per_Day, na.rm = TRUE),
physical = mean(df$Physical_Activity_Hours_Per_Day, na.rm = TRUE),
extracurricular = mean(df$Extracurricular_Hours_Per_Day, na.rm = TRUE)
)
means
## study sleep social physical extracurricular
## 7.47580 7.50125 2.70455 4.32830 1.99010
# 5. Study Hours vs GPA
plot(df$Study_Hours_Per_Day, df$GPA,
xlab = "Study Hours Per Day", ylab = "GPA",
main = "Study Hours vs GPA")
