library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.2.1 ✔ readr 2.2.0
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.3 ✔ tibble 3.3.1
## ✔ lubridate 1.9.5 ✔ tidyr 1.3.2
## ✔ purrr 1.2.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(gapminder)
glimpse(gapminder)
## Rows: 1,704
## Columns: 6
## $ country <fct> "Afghanistan", "Afghanistan", "Afghanistan", "Afghanistan", …
## $ continent <fct> Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia, …
## $ year <int> 1952, 1957, 1962, 1967, 1972, 1977, 1982, 1987, 1992, 1997, …
## $ lifeExp <dbl> 28.801, 30.332, 31.997, 34.020, 36.088, 38.438, 39.854, 40.8…
## $ pop <int> 8425333, 9240934, 10267083, 11537966, 13079460, 14880372, 12…
## $ gdpPercap <dbl> 779.4453, 820.8530, 853.1007, 836.1971, 739.9811, 786.1134, …
head(gapminder)
## # A tibble: 6 × 6
## country continent year lifeExp pop gdpPercap
## <fct> <fct> <int> <dbl> <int> <dbl>
## 1 Afghanistan Asia 1952 28.8 8425333 779.
## 2 Afghanistan Asia 1957 30.3 9240934 821.
## 3 Afghanistan Asia 1962 32.0 10267083 853.
## 4 Afghanistan Asia 1967 34.0 11537966 836.
## 5 Afghanistan Asia 1972 36.1 13079460 740.
## 6 Afghanistan Asia 1977 38.4 14880372 786.
summary(gapminder)
## country continent year lifeExp
## Afghanistan: 12 Africa :624 Min. :1952 Min. :23.60
## Albania : 12 Americas:300 1st Qu.:1966 1st Qu.:48.20
## Algeria : 12 Asia :396 Median :1980 Median :60.71
## Angola : 12 Europe :360 Mean :1980 Mean :59.47
## Argentina : 12 Oceania : 24 3rd Qu.:1993 3rd Qu.:70.85
## Australia : 12 Max. :2007 Max. :82.60
## (Other) :1632
## pop gdpPercap
## Min. :6.001e+04 Min. : 241.2
## 1st Qu.:2.794e+06 1st Qu.: 1202.1
## Median :7.024e+06 Median : 3531.8
## Mean :2.960e+07 Mean : 7215.3
## 3rd Qu.:1.959e+07 3rd Qu.: 9325.5
## Max. :1.319e+09 Max. :113523.1
##
str(gapminder)
## tibble [1,704 × 6] (S3: tbl_df/tbl/data.frame)
## $ country : Factor w/ 142 levels "Afghanistan",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ continent: Factor w/ 5 levels "Africa","Americas",..: 3 3 3 3 3 3 3 3 3 3 ...
## $ year : int [1:1704] 1952 1957 1962 1967 1972 1977 1982 1987 1992 1997 ...
## $ lifeExp : num [1:1704] 28.8 30.3 32 34 36.1 ...
## $ pop : int [1:1704] 8425333 9240934 10267083 11537966 13079460 14880372 12881816 13867957 16317921 22227415 ...
## $ gdpPercap: num [1:1704] 779 821 853 836 740 ...
colnames(gapminder)
## [1] "country" "continent" "year" "lifeExp" "pop" "gdpPercap"
gapminder%>% arrange(lifeExp)
## # A tibble: 1,704 × 6
## country continent year lifeExp pop gdpPercap
## <fct> <fct> <int> <dbl> <int> <dbl>
## 1 Rwanda Africa 1992 23.6 7290203 737.
## 2 Afghanistan Asia 1952 28.8 8425333 779.
## 3 Gambia Africa 1952 30 284320 485.
## 4 Angola Africa 1952 30.0 4232095 3521.
## 5 Sierra Leone Africa 1952 30.3 2143249 880.
## 6 Afghanistan Asia 1957 30.3 9240934 821.
## 7 Cambodia Asia 1977 31.2 6978607 525.
## 8 Mozambique Africa 1952 31.3 6446316 469.
## 9 Sierra Leone Africa 1957 31.6 2295678 1004.
## 10 Burkina Faso Africa 1952 32.0 4469979 543.
## # ℹ 1,694 more rows
gapminder%>% arrange(desc(lifeExp))
## # A tibble: 1,704 × 6
## country continent year lifeExp pop gdpPercap
## <fct> <fct> <int> <dbl> <int> <dbl>
## 1 Japan Asia 2007 82.6 127467972 31656.
## 2 Hong Kong, China Asia 2007 82.2 6980412 39725.
## 3 Japan Asia 2002 82 127065841 28605.
## 4 Iceland Europe 2007 81.8 301931 36181.
## 5 Switzerland Europe 2007 81.7 7554661 37506.
## 6 Hong Kong, China Asia 2002 81.5 6762476 30209.
## 7 Australia Oceania 2007 81.2 20434176 34435.
## 8 Spain Europe 2007 80.9 40448191 28821.
## 9 Sweden Europe 2007 80.9 9031088 33860.
## 10 Israel Asia 2007 80.7 6426679 25523.
## # ℹ 1,694 more rows
gapminder %>% arrange(gdpPercap)
## # A tibble: 1,704 × 6
## country continent year lifeExp pop gdpPercap
## <fct> <fct> <int> <dbl> <int> <dbl>
## 1 Congo, Dem. Rep. Africa 2002 45.0 55379852 241.
## 2 Congo, Dem. Rep. Africa 2007 46.5 64606759 278.
## 3 Lesotho Africa 1952 42.1 748747 299.
## 4 Guinea-Bissau Africa 1952 32.5 580653 300.
## 5 Congo, Dem. Rep. Africa 1997 42.6 47798986 312.
## 6 Eritrea Africa 1952 35.9 1438760 329.
## 7 Myanmar Asia 1952 36.3 20092996 331
## 8 Lesotho Africa 1957 45.0 813338 336.
## 9 Burundi Africa 1952 39.0 2445618 339.
## 10 Eritrea Africa 1957 38.0 1542611 344.
## # ℹ 1,694 more rows
# arrange
gapminder %>% arrange(desc(pop))
## # A tibble: 1,704 × 6
## country continent year lifeExp pop gdpPercap
## <fct> <fct> <int> <dbl> <int> <dbl>
## 1 China Asia 2007 73.0 1318683096 4959.
## 2 China Asia 2002 72.0 1280400000 3119.
## 3 China Asia 1997 70.4 1230075000 2289.
## 4 China Asia 1992 68.7 1164970000 1656.
## 5 India Asia 2007 64.7 1110396331 2452.
## 6 China Asia 1987 67.3 1084035000 1379.
## 7 India Asia 2002 62.9 1034172547 1747.
## 8 China Asia 1982 65.5 1000281000 962.
## 9 India Asia 1997 61.8 959000000 1459.
## 10 China Asia 1977 64.0 943455000 741.
## # ℹ 1,694 more rows
# filtering and arranging with one or more reason
gapminder %>% filter(year <2000 & year > 1960) %>% arrange(desc(pop)) %>% arrange(gdpPercap,lifeExp)
## # A tibble: 1,136 × 6
## country continent year lifeExp pop gdpPercap
## <fct> <fct> <int> <dbl> <int> <dbl>
## 1 Congo, Dem. Rep. Africa 1997 42.6 47798986 312.
## 2 Myanmar Asia 1992 59.3 40546538 347
## 3 Myanmar Asia 1967 49.4 25870271 349
## 4 Burundi Africa 1962 42.0 2961915 355.
## 5 Myanmar Asia 1972 53.1 28466390 357
## 6 Myanmar Asia 1977 56.1 31528087 371
## 7 Eritrea Africa 1962 40.2 1666618 381.
## 8 Myanmar Asia 1987 58.3 38028578 385
## 9 Myanmar Asia 1962 45.1 23634436 388
## 10 Mozambique Africa 1987 42.9 12891952 390.
## # ℹ 1,126 more rows
#use mutate to change or create a column
#mutate can also change whats in a column
gapminder%>% mutate(lifeExp=lifeExp*12)
## # A tibble: 1,704 × 6
## country continent year lifeExp pop gdpPercap
## <fct> <fct> <int> <dbl> <int> <dbl>
## 1 Afghanistan Asia 1952 346. 8425333 779.
## 2 Afghanistan Asia 1957 364. 9240934 821.
## 3 Afghanistan Asia 1962 384. 10267083 853.
## 4 Afghanistan Asia 1967 408. 11537966 836.
## 5 Afghanistan Asia 1972 433. 13079460 740.
## 6 Afghanistan Asia 1977 461. 14880372 786.
## 7 Afghanistan Asia 1982 478. 12881816 978.
## 8 Afghanistan Asia 1987 490. 13867957 852.
## 9 Afghanistan Asia 1992 500. 16317921 649.
## 10 Afghanistan Asia 1997 501. 22227415 635.
## # ℹ 1,694 more rows
# using mutate to create a new column
gapminder%>% mutate(lifeExpMonth=lifeExp*12)
## # A tibble: 1,704 × 7
## country continent year lifeExp pop gdpPercap lifeExpMonth
## <fct> <fct> <int> <dbl> <int> <dbl> <dbl>
## 1 Afghanistan Asia 1952 28.8 8425333 779. 346.
## 2 Afghanistan Asia 1957 30.3 9240934 821. 364.
## 3 Afghanistan Asia 1962 32.0 10267083 853. 384.
## 4 Afghanistan Asia 1967 34.0 11537966 836. 408.
## 5 Afghanistan Asia 1972 36.1 13079460 740. 433.
## 6 Afghanistan Asia 1977 38.4 14880372 786. 461.
## 7 Afghanistan Asia 1982 39.9 12881816 978. 478.
## 8 Afghanistan Asia 1987 40.8 13867957 852. 490.
## 9 Afghanistan Asia 1992 41.7 16317921 649. 500.
## 10 Afghanistan Asia 1997 41.8 22227415 635. 501.
## # ℹ 1,694 more rows
gapminder1 <- gapminder%>% mutate(lifeExpMonth=lifeExp*12)
gapminder1
## # A tibble: 1,704 × 7
## country continent year lifeExp pop gdpPercap lifeExpMonth
## <fct> <fct> <int> <dbl> <int> <dbl> <dbl>
## 1 Afghanistan Asia 1952 28.8 8425333 779. 346.
## 2 Afghanistan Asia 1957 30.3 9240934 821. 364.
## 3 Afghanistan Asia 1962 32.0 10267083 853. 384.
## 4 Afghanistan Asia 1967 34.0 11537966 836. 408.
## 5 Afghanistan Asia 1972 36.1 13079460 740. 433.
## 6 Afghanistan Asia 1977 38.4 14880372 786. 461.
## 7 Afghanistan Asia 1982 39.9 12881816 978. 478.
## 8 Afghanistan Asia 1987 40.8 13867957 852. 490.
## 9 Afghanistan Asia 1992 41.7 16317921 649. 500.
## 10 Afghanistan Asia 1997 41.8 22227415 635. 501.
## # ℹ 1,694 more rows
# combining filter,mutate and arrange
gapminder%>% filter(year==2007) %>% mutate(lifeExpmonth = 12*lifeExp) %>% arrange(desc(lifeExpmonth))
## # A tibble: 142 × 7
## country continent year lifeExp pop gdpPercap lifeExpmonth
## <fct> <fct> <int> <dbl> <int> <dbl> <dbl>
## 1 Japan Asia 2007 82.6 127467972 31656. 991.
## 2 Hong Kong, China Asia 2007 82.2 6980412 39725. 986.
## 3 Iceland Europe 2007 81.8 301931 36181. 981.
## 4 Switzerland Europe 2007 81.7 7554661 37506. 980.
## 5 Australia Oceania 2007 81.2 20434176 34435. 975.
## 6 Spain Europe 2007 80.9 40448191 28821. 971.
## 7 Sweden Europe 2007 80.9 9031088 33860. 971.
## 8 Israel Asia 2007 80.7 6426679 25523. 969.
## 9 France Europe 2007 80.7 61083916 30470. 968.
## 10 Canada Americas 2007 80.7 33390141 36319. 968.
## # ℹ 132 more rows
# assignment
getwd()
## [1] "C:/Users/HP/Desktop/miracle"
mygamingfile <- read_csv("C:\\Users\\HP\\Desktop\\miracle\\gaming_addiction.csv")
## Rows: 250 Columns: 49
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (13): user_id, gender, country, occupation, income_level, preferred_genr...
## dbl (36): age, years_gaming, daily_playtime_hours, weekly_play_sessions, lat...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
mygamingfile
## # A tibble: 250 × 49
## user_id age gender country occupation income_level years_gaming
## <chr> <dbl> <chr> <chr> <chr> <chr> <dbl>
## 1 USR000001 21 Male India Employed Middle 9
## 2 USR000002 25 Male India Employed Lower-Middle 13
## 3 USR000003 26 Male Brazil Employed Middle 14
## 4 USR000004 22 Male South Korea Employed Upper-Middle 10
## 5 USR000005 17 Female India Student Middle 5
## 6 USR000006 13 Male USA Freelancer Middle 1
## 7 USR000007 27 Male UK Unemployed Lower-Middle 15
## 8 USR000008 18 Non-binary Canada Student Middle 6
## 9 USR000009 16 Female USA Student High 1
## 10 USR000010 30 Female Brazil Freelancer Middle 18
## # ℹ 240 more rows
## # ℹ 42 more variables: preferred_genre <chr>, platform <chr>,
## # device_type <chr>, rank_tier <chr>, daily_playtime_hours <dbl>,
## # weekly_play_sessions <dbl>, late_night_sessions_hours <dbl>,
## # weekend_playtime_hours <dbl>, consecutive_hours_max <dbl>,
## # multiplayer_ratio <dbl>, toxic_chat_reports <dbl>,
## # rage_quit_frequency <dbl>, in_game_purchases <dbl>, …
head(mygamingfile)
## # A tibble: 6 × 49
## user_id age gender country occupation income_level years_gaming
## <chr> <dbl> <chr> <chr> <chr> <chr> <dbl>
## 1 USR000001 21 Male India Employed Middle 9
## 2 USR000002 25 Male India Employed Lower-Middle 13
## 3 USR000003 26 Male Brazil Employed Middle 14
## 4 USR000004 22 Male South Korea Employed Upper-Middle 10
## 5 USR000005 17 Female India Student Middle 5
## 6 USR000006 13 Male USA Freelancer Middle 1
## # ℹ 42 more variables: preferred_genre <chr>, platform <chr>,
## # device_type <chr>, rank_tier <chr>, daily_playtime_hours <dbl>,
## # weekly_play_sessions <dbl>, late_night_sessions_hours <dbl>,
## # weekend_playtime_hours <dbl>, consecutive_hours_max <dbl>,
## # multiplayer_ratio <dbl>, toxic_chat_reports <dbl>,
## # rage_quit_frequency <dbl>, in_game_purchases <dbl>,
## # monthly_spending_usd <dbl>, lootbox_openings <dbl>, …
summary(mygamingfile)
## user_id age gender country
## Length :250 Min. :13.00 Length :250 Length :250
## N.unique :250 1st Qu.:18.00 N.unique : 4 N.unique : 15
## N.blank : 0 Median :22.00 N.blank : 0 N.blank : 0
## Min.nchar: 9 Mean :22.16 Min.nchar: 4 Min.nchar: 2
## Max.nchar: 9 3rd Qu.:27.00 Max.nchar: 17 Max.nchar: 11
## Max. :40.00
##
## occupation income_level years_gaming preferred_genre
## Length :250 Length :250 Min. : 1.000 Length :250
## N.unique : 5 N.unique : 5 1st Qu.: 6.000 N.unique : 10
## N.blank : 0 N.blank : 0 Median : 9.000 N.blank : 0
## Min.nchar: 7 Min.nchar: 3 Mean : 9.668 Min.nchar: 3
## Max.nchar: 24 Max.nchar: 12 3rd Qu.:14.750 Max.nchar: 13
## Max. :25.000
##
## platform device_type rank_tier daily_playtime_hours
## Length :250 Length :250 Length :250 Min. : 0.500
## N.unique : 5 N.unique : 6 N.unique : 8 1st Qu.: 4.225
## N.blank : 0 N.blank : 0 N.blank : 0 Median : 6.450
## Min.nchar: 2 Min.nchar: 5 Min.nchar: 4 Mean : 6.153
## Max.nchar: 10 Max.nchar: 12 Max.nchar: 11 3rd Qu.: 8.175
## Max. :11.900
##
## weekly_play_sessions late_night_sessions_hours weekend_playtime_hours
## Min. : 1.000 Min. :0.000 Min. : 0.500
## 1st Qu.: 4.000 1st Qu.:1.125 1st Qu.: 5.600
## Median : 7.000 Median :2.100 Median : 8.150
## Mean : 7.056 Mean :2.102 Mean : 8.368
## 3rd Qu.:10.000 3rd Qu.:3.000 3rd Qu.:10.850
## Max. :15.000 Max. :5.200 Max. :20.000
##
## consecutive_hours_max multiplayer_ratio toxic_chat_reports rage_quit_frequency
## Min. : 1.000 Min. :0.0000 Min. : 0.000 Min. : 0.000
## 1st Qu.: 5.525 1st Qu.:0.3000 1st Qu.: 0.000 1st Qu.: 0.000
## Median :10.100 Median :0.4500 Median : 1.000 Median : 1.000
## Mean : 9.715 Mean :0.4622 Mean : 2.948 Mean : 1.896
## 3rd Qu.:13.175 3rd Qu.:0.6300 3rd Qu.: 2.000 3rd Qu.: 3.000
## Max. :20.600 Max. :1.0000 Max. :32.000 Max. :10.000
##
## in_game_purchases monthly_spending_usd lootbox_openings subscription_status
## Min. : 0.000 Min. : 0.00 Min. : 0.000 Length :250
## 1st Qu.: 0.000 1st Qu.: 15.91 1st Qu.: 3.000 N.unique : 4
## Median : 3.000 Median : 35.71 Median : 7.000 N.blank : 0
## Mean : 4.072 Mean : 41.12 Mean : 8.468 Min.nchar: 4
## 3rd Qu.: 7.000 3rd Qu.: 57.72 3rd Qu.:12.000 Max.nchar: 8
## Max. :21.000 Max. :182.60 Max. :41.000
##
## stress_score loneliness_score dopamine_dependency_index self_control_score
## Min. : 1.000 Min. : 1.00 Min. :1.000 Min. : 1.000
## 1st Qu.: 5.700 1st Qu.: 3.70 1st Qu.:2.925 1st Qu.: 5.100
## Median : 6.950 Median : 4.90 Median :4.400 Median : 6.500
## Mean : 6.819 Mean : 5.06 Mean :4.312 Mean : 6.463
## 3rd Qu.: 8.000 3rd Qu.: 6.50 3rd Qu.:5.675 3rd Qu.: 7.900
## Max. :10.000 Max. :10.00 Max. :8.600 Max. :10.000
##
## impulsiveness_score anxiety_level depression_indicator emotional_stability
## Min. : 1.000 Min. : 1.000 Min. :1.000 Min. : 2.300
## 1st Qu.: 3.700 1st Qu.: 4.425 1st Qu.:3.500 1st Qu.: 5.300
## Median : 5.000 Median : 5.600 Median :4.500 Median : 6.600
## Mean : 4.908 Mean : 5.608 Mean :4.611 Mean : 6.496
## 3rd Qu.: 6.300 3rd Qu.: 6.675 3rd Qu.:5.900 3rd Qu.: 7.600
## Max. :10.000 Max. :10.000 Max. :8.600 Max. :10.000
## NAs :11
## sleep_hours exercise_frequency_per_week caffeine_intake_cups_day
## Min. :3.400 Min. :0.000 Min. :0.000
## 1st Qu.:6.100 1st Qu.:0.000 1st Qu.:1.000
## Median :6.800 Median :1.000 Median :2.000
## Mean :6.766 Mean :1.392 Mean :2.456
## 3rd Qu.:7.700 3rd Qu.:2.000 3rd Qu.:4.000
## Max. :9.500 Max. :5.000 Max. :7.000
##
## social_interaction_hours relationship_status gpa_or_performance_score
## Min. :0.000 Length :250 Min. :2.170
## 1st Qu.:1.000 N.unique : 5 1st Qu.:3.478
## Median :2.000 N.blank : 0 Median :4.000
## Mean :2.139 Min.nchar: 6 Mean :3.732
## 3rd Qu.:3.300 Max.nchar: 17 3rd Qu.:4.000
## Max. :6.600 Max. :4.000
## NAs :10
## missed_deadlines productivity_drop_percent absenteeism_days
## Min. :0.000 Min. : 0.00 Min. : 0.000
## 1st Qu.:1.000 1st Qu.: 8.15 1st Qu.: 3.000
## Median :3.000 Median :15.90 Median : 6.000
## Mean :2.828 Mean :15.99 Mean : 5.524
## 3rd Qu.:4.000 3rd Qu.:22.98 3rd Qu.: 8.000
## Max. :8.000 Max. :44.20 Max. :14.000
##
## internet_speed_mbps screen_time_total_hours behavioral_cluster addiction_score
## Min. : 5.00 Min. : 1.20 Length :250 Min. :12.28
## 1st Qu.: 61.38 1st Qu.: 6.20 N.unique : 7 1st Qu.:29.88
## Median : 99.15 Median : 8.20 N.blank : 0 Median :39.88
## Mean : 99.25 Mean : 8.24 Min.nchar: 12 Mean :38.74
## 3rd Qu.:133.57 3rd Qu.:10.50 Max.nchar: 19 3rd Qu.:47.11
## Max. :255.50 Max. :15.10 Max. :68.00
##
## addiction_binary addiction_severity burnout_probability
## Min. :0.000 Length :250 Min. :0.3200
## 1st Qu.:0.000 N.unique : 4 1st Qu.:1.0000
## Median :0.000 N.blank : 0 Median :1.0000
## Mean :0.168 Min.nchar: 4 Mean :0.9969
## 3rd Qu.:0.000 Max.nchar: 8 3rd Qu.:1.0000
## Max. :1.000 Max. :1.0000
##
## mental_health_risk_score churn_probability
## Min. :0.1200 Min. :0.1500
## 1st Qu.:0.4062 1st Qu.:0.7322
## Median :0.5150 Median :0.8080
## Mean :0.5096 Mean :0.7956
## 3rd Qu.:0.6000 3rd Qu.:0.8780
## Max. :0.9200 Max. :1.0000
##
glimpse(mygamingfile)
## Rows: 250
## Columns: 49
## $ user_id <chr> "USR000001", "USR000002", "USR000003", "US…
## $ age <dbl> 21, 25, 26, 22, 17, 13, 27, 18, 16, 30, 18…
## $ gender <chr> "Male", "Male", "Male", "Male", "Female", …
## $ country <chr> "India", "India", "Brazil", "South Korea",…
## $ occupation <chr> "Employed", "Employed", "Employed", "Emplo…
## $ income_level <chr> "Middle", "Lower-Middle", "Middle", "Upper…
## $ years_gaming <dbl> 9, 13, 14, 10, 5, 1, 15, 6, 1, 18, 6, 9, 7…
## $ preferred_genre <chr> "Sandbox", "RPG", "RPG", "Strategy", "Stra…
## $ platform <chr> "PC", "Mobile", "PC+Mobile", "PC+Mobile", …
## $ device_type <chr> "Laptop", "Mixed", "High-end PC", "Mobile"…
## $ rank_tier <chr> "Gold", "Bronze", "Master", "Bronze", "Bro…
## $ daily_playtime_hours <dbl> 3.5, 10.9, 8.6, 5.9, 7.4, 1.4, 8.0, 2.2, 8…
## $ weekly_play_sessions <dbl> 4, 14, 7, 5, 8, 1, 10, 3, 12, 8, 9, 10, 7,…
## $ late_night_sessions_hours <dbl> 1.0, 3.2, 2.4, 1.1, 3.2, 0.0, 2.9, 0.2, 1.…
## $ weekend_playtime_hours <dbl> 4.9, 14.7, 11.6, 13.6, 6.3, 1.7, 10.6, 3.2…
## $ consecutive_hours_max <dbl> 6.5, 15.9, 13.1, 8.2, 14.2, 3.5, 12.3, 5.1…
## $ multiplayer_ratio <dbl> 0.67, 0.44, 0.32, 0.23, 0.57, 0.35, 0.49, …
## $ toxic_chat_reports <dbl> 0, 2, 0, 7, 4, 0, 17, 1, 6, 9, 7, 0, 0, 0,…
## $ rage_quit_frequency <dbl> 0, 0, 1, 7, 2, 0, 7, 0, 6, 7, 2, 0, 0, 2, …
## $ in_game_purchases <dbl> 0, 7, 3, 9, 5, 9, 7, 3, 13, 0, 5, 4, 0, 4,…
## $ monthly_spending_usd <dbl> 38.67, 47.35, 37.80, 74.51, 25.32, 18.71, …
## $ lootbox_openings <dbl> 10, 18, 4, 15, 0, 0, 9, 2, 22, 14, 1, 7, 0…
## $ subscription_status <chr> "None", "Premium", "Ultimate", "None", "Pr…
## $ stress_score <dbl> 8.2, 7.8, 8.4, 6.0, 8.0, 1.0, 7.6, 4.6, 8.…
## $ loneliness_score <dbl> 8.8, 5.6, 4.1, 4.5, 4.2, 7.2, 5.5, 6.9, 3.…
## $ dopamine_dependency_index <dbl> 2.7, 8.2, 5.0, 6.0, 6.2, 2.2, 4.6, 1.4, 6.…
## $ self_control_score <dbl> 7.0, 6.5, 4.2, 5.8, 6.5, 7.0, 8.4, 4.7, 10…
## $ impulsiveness_score <dbl> 5.1, 3.5, 6.1, 3.6, 5.0, 4.2, 4.3, 3.9, 2.…
## $ anxiety_level <dbl> 9.9, 6.2, 7.7, 5.9, 8.4, 3.0, 5.8, 4.7, 4.…
## $ depression_indicator <dbl> 8.5, 4.1, 6.7, 4.5, 3.3, 5.0, 5.2, 5.1, 3.…
## $ emotional_stability <dbl> 3.7, 3.0, 3.3, 6.5, 5.5, 10.0, 3.9, 8.5, 3…
## $ sleep_hours <dbl> 6.3, 6.1, 6.1, 6.7, 7.6, 7.2, 8.0, 7.3, 7.…
## $ exercise_frequency_per_week <dbl> 2, 0, 1, 4, 1, 3, 1, 0, 0, 2, 0, 2, 1, 0, …
## $ caffeine_intake_cups_day <dbl> 0, 2, 3, 5, 0, 1, 3, 0, 3, 1, 4, 0, 0, 2, …
## $ social_interaction_hours <dbl> 2.7, 3.5, 2.0, 0.6, 1.2, 3.1, 0.5, 3.6, 4.…
## $ relationship_status <chr> "In a relationship", "In a relationship", …
## $ gpa_or_performance_score <dbl> 4.00, 4.00, 4.00, 4.00, 2.60, 4.00, 4.00, …
## $ missed_deadlines <dbl> 4, 4, 6, 3, 3, 0, 2, 2, 3, 2, 8, 1, 1, 3, …
## $ productivity_drop_percent <dbl> 0.0, 16.7, 8.5, 8.7, 21.9, 0.0, 30.2, 0.0,…
## $ absenteeism_days <dbl> 7, 6, 7, 8, 6, 3, 12, 5, 5, 3, 0, 3, 4, 3,…
## $ internet_speed_mbps <dbl> 39.9, 71.5, 119.4, 136.5, 78.8, 93.8, 5.0,…
## $ screen_time_total_hours <dbl> 5.4, 13.4, 12.3, 6.9, 9.3, 3.7, 10.0, 4.7,…
## $ behavioral_cluster <chr> "Casual Enjoyer", "Streamer/Creator", "Str…
## $ addiction_score <dbl> 27.61, 55.51, 45.85, 39.87, 46.97, 17.26, …
## $ addiction_binary <dbl> 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, …
## $ addiction_severity <chr> "Mild", "Moderate", "Moderate", "Mild", "M…
## $ burnout_probability <dbl> 1.000, 1.000, 1.000, 1.000, 1.000, 0.320, …
## $ mental_health_risk_score <dbl> 0.920, 0.515, 0.720, 0.520, 0.585, 0.400, …
## $ churn_probability <dbl> 1.000, 0.813, 0.947, 0.660, 0.867, 0.150, …
# using filter
## showing the students that are frrom USA
mygamingfile %>% filter(country == "USA" & occupation == "Student")
## # A tibble: 16 × 49
## user_id age gender country occupation income_level years_gaming
## <chr> <dbl> <chr> <chr> <chr> <chr> <dbl>
## 1 USR000009 16 Female USA Student High 1
## 2 USR000032 15 Male USA Student Middle 3
## 3 USR000054 13 Male USA Student Lower-Middle 1
## 4 USR000069 17 Male USA Student Middle 3
## 5 USR000072 28 Female USA Student Low 13
## 6 USR000081 21 Female USA Student Lower-Middle 9
## 7 USR000085 20 Male USA Student Middle 8
## 8 USR000120 13 Female USA Student Middle 1
## 9 USR000128 13 Female USA Student Middle 1
## 10 USR000159 18 Male USA Student Lower-Middle 4
## 11 USR000170 13 Male USA Student Lower-Middle 1
## 12 USR000198 13 Male USA Student Middle 1
## 13 USR000204 27 Non-binary USA Student Low 15
## 14 USR000214 28 Female USA Student Middle 16
## 15 USR000238 19 Female USA Student Lower-Middle 4
## 16 USR000248 20 Male USA Student Middle 8
## # ℹ 42 more variables: preferred_genre <chr>, platform <chr>,
## # device_type <chr>, rank_tier <chr>, daily_playtime_hours <dbl>,
## # weekly_play_sessions <dbl>, late_night_sessions_hours <dbl>,
## # weekend_playtime_hours <dbl>, consecutive_hours_max <dbl>,
## # multiplayer_ratio <dbl>, toxic_chat_reports <dbl>,
## # rage_quit_frequency <dbl>, in_game_purchases <dbl>,
## # monthly_spending_usd <dbl>, lootbox_openings <dbl>, …
mygamingfile %>% filter(age >= 17 & occupation == "Employed" & relationship_status == "In a relationship")
## # A tibble: 35 × 49
## user_id age gender country occupation income_level years_gaming
## <chr> <dbl> <chr> <chr> <chr> <chr> <dbl>
## 1 USR000001 21 Male India Employed Middle 9
## 2 USR000002 25 Male India Employed Lower-Middle 13
## 3 USR000018 20 Male Germany Employed Low 7
## 4 USR000027 28 Female India Employed Low 16
## 5 USR000037 27 Male India Employed Low 15
## 6 USR000044 26 Male USA Employed Middle 14
## 7 USR000050 26 Male UK Employed Lower-Middle 14
## 8 USR000068 20 Female Australia Employed Middle 6
## 9 USR000070 22 Non-binary China Employed Upper-Middle 10
## 10 USR000073 28 Male Canada Employed Lower-Middle 16
## # ℹ 25 more rows
## # ℹ 42 more variables: preferred_genre <chr>, platform <chr>,
## # device_type <chr>, rank_tier <chr>, daily_playtime_hours <dbl>,
## # weekly_play_sessions <dbl>, late_night_sessions_hours <dbl>,
## # weekend_playtime_hours <dbl>, consecutive_hours_max <dbl>,
## # multiplayer_ratio <dbl>, toxic_chat_reports <dbl>,
## # rage_quit_frequency <dbl>, in_game_purchases <dbl>, …
mygamingfile %>% arrange(desc(age))
## # A tibble: 250 × 49
## user_id age gender country occupation income_level years_gaming
## <chr> <dbl> <chr> <chr> <chr> <chr> <dbl>
## 1 USR000098 40 Male USA Employed Middle 25
## 2 USR000244 37 Male Germany Employed Upper-Middle 25
## 3 USR000076 35 Male Brazil Employed Upper-Middle 23
## 4 USR000219 35 Male USA Employed Low 19
## 5 USR000142 34 Male UK Freelancer High 21
## 6 USR000062 33 Male USA Employed Lower-Middle 21
## 7 USR000166 32 Female India Employed Middle 20
## 8 USR000171 32 Male India Employed Lower-Middle 20
## 9 USR000038 31 Female India Employed Upper-Middle 19
## 10 USR000057 31 Male India Employed Lower-Middle 19
## # ℹ 240 more rows
## # ℹ 42 more variables: preferred_genre <chr>, platform <chr>,
## # device_type <chr>, rank_tier <chr>, daily_playtime_hours <dbl>,
## # weekly_play_sessions <dbl>, late_night_sessions_hours <dbl>,
## # weekend_playtime_hours <dbl>, consecutive_hours_max <dbl>,
## # multiplayer_ratio <dbl>, toxic_chat_reports <dbl>,
## # rage_quit_frequency <dbl>, in_game_purchases <dbl>, …
#checking for
mygamingfile %>% filter(relationship_status == "In a relationship") %>% arrange(desc(emotional_stability))
## # A tibble: 85 × 49
## user_id age gender country occupation income_level years_gaming
## <chr> <dbl> <chr> <chr> <chr> <chr> <dbl>
## 1 USR000006 13 Male USA Freelancer Middle 1
## 2 USR000073 28 Male Canada Employed Lower-Middle 16
## 3 USR000021 13 Male India Student Middle 1
## 4 USR000131 29 Male Germany Employed Lower-Middle 17
## 5 USR000054 13 Male USA Student Lower-Middle 1
## 6 USR000212 19 Female China Unemployed Lower-Middle 7
## 7 USR000102 21 Male USA Employed Lower-Middle 9
## 8 USR000111 18 Male USA Employed Lower-Middle 6
## 9 USR000069 17 Male USA Student Middle 3
## 10 USR000144 15 Male Russia Employed High 3
## # ℹ 75 more rows
## # ℹ 42 more variables: preferred_genre <chr>, platform <chr>,
## # device_type <chr>, rank_tier <chr>, daily_playtime_hours <dbl>,
## # weekly_play_sessions <dbl>, late_night_sessions_hours <dbl>,
## # weekend_playtime_hours <dbl>, consecutive_hours_max <dbl>,
## # multiplayer_ratio <dbl>, toxic_chat_reports <dbl>,
## # rage_quit_frequency <dbl>, in_game_purchases <dbl>, …
# GETTING COLUMN NAMES
colnames(mygamingfile)
## [1] "user_id" "age"
## [3] "gender" "country"
## [5] "occupation" "income_level"
## [7] "years_gaming" "preferred_genre"
## [9] "platform" "device_type"
## [11] "rank_tier" "daily_playtime_hours"
## [13] "weekly_play_sessions" "late_night_sessions_hours"
## [15] "weekend_playtime_hours" "consecutive_hours_max"
## [17] "multiplayer_ratio" "toxic_chat_reports"
## [19] "rage_quit_frequency" "in_game_purchases"
## [21] "monthly_spending_usd" "lootbox_openings"
## [23] "subscription_status" "stress_score"
## [25] "loneliness_score" "dopamine_dependency_index"
## [27] "self_control_score" "impulsiveness_score"
## [29] "anxiety_level" "depression_indicator"
## [31] "emotional_stability" "sleep_hours"
## [33] "exercise_frequency_per_week" "caffeine_intake_cups_day"
## [35] "social_interaction_hours" "relationship_status"
## [37] "gpa_or_performance_score" "missed_deadlines"
## [39] "productivity_drop_percent" "absenteeism_days"
## [41] "internet_speed_mbps" "screen_time_total_hours"
## [43] "behavioral_cluster" "addiction_score"
## [45] "addiction_binary" "addiction_severity"
## [47] "burnout_probability" "mental_health_risk_score"
## [49] "churn_probability"
glimpse(mygamingfile)
## Rows: 250
## Columns: 49
## $ user_id <chr> "USR000001", "USR000002", "USR000003", "US…
## $ age <dbl> 21, 25, 26, 22, 17, 13, 27, 18, 16, 30, 18…
## $ gender <chr> "Male", "Male", "Male", "Male", "Female", …
## $ country <chr> "India", "India", "Brazil", "South Korea",…
## $ occupation <chr> "Employed", "Employed", "Employed", "Emplo…
## $ income_level <chr> "Middle", "Lower-Middle", "Middle", "Upper…
## $ years_gaming <dbl> 9, 13, 14, 10, 5, 1, 15, 6, 1, 18, 6, 9, 7…
## $ preferred_genre <chr> "Sandbox", "RPG", "RPG", "Strategy", "Stra…
## $ platform <chr> "PC", "Mobile", "PC+Mobile", "PC+Mobile", …
## $ device_type <chr> "Laptop", "Mixed", "High-end PC", "Mobile"…
## $ rank_tier <chr> "Gold", "Bronze", "Master", "Bronze", "Bro…
## $ daily_playtime_hours <dbl> 3.5, 10.9, 8.6, 5.9, 7.4, 1.4, 8.0, 2.2, 8…
## $ weekly_play_sessions <dbl> 4, 14, 7, 5, 8, 1, 10, 3, 12, 8, 9, 10, 7,…
## $ late_night_sessions_hours <dbl> 1.0, 3.2, 2.4, 1.1, 3.2, 0.0, 2.9, 0.2, 1.…
## $ weekend_playtime_hours <dbl> 4.9, 14.7, 11.6, 13.6, 6.3, 1.7, 10.6, 3.2…
## $ consecutive_hours_max <dbl> 6.5, 15.9, 13.1, 8.2, 14.2, 3.5, 12.3, 5.1…
## $ multiplayer_ratio <dbl> 0.67, 0.44, 0.32, 0.23, 0.57, 0.35, 0.49, …
## $ toxic_chat_reports <dbl> 0, 2, 0, 7, 4, 0, 17, 1, 6, 9, 7, 0, 0, 0,…
## $ rage_quit_frequency <dbl> 0, 0, 1, 7, 2, 0, 7, 0, 6, 7, 2, 0, 0, 2, …
## $ in_game_purchases <dbl> 0, 7, 3, 9, 5, 9, 7, 3, 13, 0, 5, 4, 0, 4,…
## $ monthly_spending_usd <dbl> 38.67, 47.35, 37.80, 74.51, 25.32, 18.71, …
## $ lootbox_openings <dbl> 10, 18, 4, 15, 0, 0, 9, 2, 22, 14, 1, 7, 0…
## $ subscription_status <chr> "None", "Premium", "Ultimate", "None", "Pr…
## $ stress_score <dbl> 8.2, 7.8, 8.4, 6.0, 8.0, 1.0, 7.6, 4.6, 8.…
## $ loneliness_score <dbl> 8.8, 5.6, 4.1, 4.5, 4.2, 7.2, 5.5, 6.9, 3.…
## $ dopamine_dependency_index <dbl> 2.7, 8.2, 5.0, 6.0, 6.2, 2.2, 4.6, 1.4, 6.…
## $ self_control_score <dbl> 7.0, 6.5, 4.2, 5.8, 6.5, 7.0, 8.4, 4.7, 10…
## $ impulsiveness_score <dbl> 5.1, 3.5, 6.1, 3.6, 5.0, 4.2, 4.3, 3.9, 2.…
## $ anxiety_level <dbl> 9.9, 6.2, 7.7, 5.9, 8.4, 3.0, 5.8, 4.7, 4.…
## $ depression_indicator <dbl> 8.5, 4.1, 6.7, 4.5, 3.3, 5.0, 5.2, 5.1, 3.…
## $ emotional_stability <dbl> 3.7, 3.0, 3.3, 6.5, 5.5, 10.0, 3.9, 8.5, 3…
## $ sleep_hours <dbl> 6.3, 6.1, 6.1, 6.7, 7.6, 7.2, 8.0, 7.3, 7.…
## $ exercise_frequency_per_week <dbl> 2, 0, 1, 4, 1, 3, 1, 0, 0, 2, 0, 2, 1, 0, …
## $ caffeine_intake_cups_day <dbl> 0, 2, 3, 5, 0, 1, 3, 0, 3, 1, 4, 0, 0, 2, …
## $ social_interaction_hours <dbl> 2.7, 3.5, 2.0, 0.6, 1.2, 3.1, 0.5, 3.6, 4.…
## $ relationship_status <chr> "In a relationship", "In a relationship", …
## $ gpa_or_performance_score <dbl> 4.00, 4.00, 4.00, 4.00, 2.60, 4.00, 4.00, …
## $ missed_deadlines <dbl> 4, 4, 6, 3, 3, 0, 2, 2, 3, 2, 8, 1, 1, 3, …
## $ productivity_drop_percent <dbl> 0.0, 16.7, 8.5, 8.7, 21.9, 0.0, 30.2, 0.0,…
## $ absenteeism_days <dbl> 7, 6, 7, 8, 6, 3, 12, 5, 5, 3, 0, 3, 4, 3,…
## $ internet_speed_mbps <dbl> 39.9, 71.5, 119.4, 136.5, 78.8, 93.8, 5.0,…
## $ screen_time_total_hours <dbl> 5.4, 13.4, 12.3, 6.9, 9.3, 3.7, 10.0, 4.7,…
## $ behavioral_cluster <chr> "Casual Enjoyer", "Streamer/Creator", "Str…
## $ addiction_score <dbl> 27.61, 55.51, 45.85, 39.87, 46.97, 17.26, …
## $ addiction_binary <dbl> 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, …
## $ addiction_severity <chr> "Mild", "Moderate", "Moderate", "Mild", "M…
## $ burnout_probability <dbl> 1.000, 1.000, 1.000, 1.000, 1.000, 0.320, …
## $ mental_health_risk_score <dbl> 0.920, 0.515, 0.720, 0.520, 0.585, 0.400, …
## $ churn_probability <dbl> 1.000, 0.813, 0.947, 0.660, 0.867, 0.150, …
summary(mygamingfile)
## user_id age gender country
## Length :250 Min. :13.00 Length :250 Length :250
## N.unique :250 1st Qu.:18.00 N.unique : 4 N.unique : 15
## N.blank : 0 Median :22.00 N.blank : 0 N.blank : 0
## Min.nchar: 9 Mean :22.16 Min.nchar: 4 Min.nchar: 2
## Max.nchar: 9 3rd Qu.:27.00 Max.nchar: 17 Max.nchar: 11
## Max. :40.00
##
## occupation income_level years_gaming preferred_genre
## Length :250 Length :250 Min. : 1.000 Length :250
## N.unique : 5 N.unique : 5 1st Qu.: 6.000 N.unique : 10
## N.blank : 0 N.blank : 0 Median : 9.000 N.blank : 0
## Min.nchar: 7 Min.nchar: 3 Mean : 9.668 Min.nchar: 3
## Max.nchar: 24 Max.nchar: 12 3rd Qu.:14.750 Max.nchar: 13
## Max. :25.000
##
## platform device_type rank_tier daily_playtime_hours
## Length :250 Length :250 Length :250 Min. : 0.500
## N.unique : 5 N.unique : 6 N.unique : 8 1st Qu.: 4.225
## N.blank : 0 N.blank : 0 N.blank : 0 Median : 6.450
## Min.nchar: 2 Min.nchar: 5 Min.nchar: 4 Mean : 6.153
## Max.nchar: 10 Max.nchar: 12 Max.nchar: 11 3rd Qu.: 8.175
## Max. :11.900
##
## weekly_play_sessions late_night_sessions_hours weekend_playtime_hours
## Min. : 1.000 Min. :0.000 Min. : 0.500
## 1st Qu.: 4.000 1st Qu.:1.125 1st Qu.: 5.600
## Median : 7.000 Median :2.100 Median : 8.150
## Mean : 7.056 Mean :2.102 Mean : 8.368
## 3rd Qu.:10.000 3rd Qu.:3.000 3rd Qu.:10.850
## Max. :15.000 Max. :5.200 Max. :20.000
##
## consecutive_hours_max multiplayer_ratio toxic_chat_reports rage_quit_frequency
## Min. : 1.000 Min. :0.0000 Min. : 0.000 Min. : 0.000
## 1st Qu.: 5.525 1st Qu.:0.3000 1st Qu.: 0.000 1st Qu.: 0.000
## Median :10.100 Median :0.4500 Median : 1.000 Median : 1.000
## Mean : 9.715 Mean :0.4622 Mean : 2.948 Mean : 1.896
## 3rd Qu.:13.175 3rd Qu.:0.6300 3rd Qu.: 2.000 3rd Qu.: 3.000
## Max. :20.600 Max. :1.0000 Max. :32.000 Max. :10.000
##
## in_game_purchases monthly_spending_usd lootbox_openings subscription_status
## Min. : 0.000 Min. : 0.00 Min. : 0.000 Length :250
## 1st Qu.: 0.000 1st Qu.: 15.91 1st Qu.: 3.000 N.unique : 4
## Median : 3.000 Median : 35.71 Median : 7.000 N.blank : 0
## Mean : 4.072 Mean : 41.12 Mean : 8.468 Min.nchar: 4
## 3rd Qu.: 7.000 3rd Qu.: 57.72 3rd Qu.:12.000 Max.nchar: 8
## Max. :21.000 Max. :182.60 Max. :41.000
##
## stress_score loneliness_score dopamine_dependency_index self_control_score
## Min. : 1.000 Min. : 1.00 Min. :1.000 Min. : 1.000
## 1st Qu.: 5.700 1st Qu.: 3.70 1st Qu.:2.925 1st Qu.: 5.100
## Median : 6.950 Median : 4.90 Median :4.400 Median : 6.500
## Mean : 6.819 Mean : 5.06 Mean :4.312 Mean : 6.463
## 3rd Qu.: 8.000 3rd Qu.: 6.50 3rd Qu.:5.675 3rd Qu.: 7.900
## Max. :10.000 Max. :10.00 Max. :8.600 Max. :10.000
##
## impulsiveness_score anxiety_level depression_indicator emotional_stability
## Min. : 1.000 Min. : 1.000 Min. :1.000 Min. : 2.300
## 1st Qu.: 3.700 1st Qu.: 4.425 1st Qu.:3.500 1st Qu.: 5.300
## Median : 5.000 Median : 5.600 Median :4.500 Median : 6.600
## Mean : 4.908 Mean : 5.608 Mean :4.611 Mean : 6.496
## 3rd Qu.: 6.300 3rd Qu.: 6.675 3rd Qu.:5.900 3rd Qu.: 7.600
## Max. :10.000 Max. :10.000 Max. :8.600 Max. :10.000
## NAs :11
## sleep_hours exercise_frequency_per_week caffeine_intake_cups_day
## Min. :3.400 Min. :0.000 Min. :0.000
## 1st Qu.:6.100 1st Qu.:0.000 1st Qu.:1.000
## Median :6.800 Median :1.000 Median :2.000
## Mean :6.766 Mean :1.392 Mean :2.456
## 3rd Qu.:7.700 3rd Qu.:2.000 3rd Qu.:4.000
## Max. :9.500 Max. :5.000 Max. :7.000
##
## social_interaction_hours relationship_status gpa_or_performance_score
## Min. :0.000 Length :250 Min. :2.170
## 1st Qu.:1.000 N.unique : 5 1st Qu.:3.478
## Median :2.000 N.blank : 0 Median :4.000
## Mean :2.139 Min.nchar: 6 Mean :3.732
## 3rd Qu.:3.300 Max.nchar: 17 3rd Qu.:4.000
## Max. :6.600 Max. :4.000
## NAs :10
## missed_deadlines productivity_drop_percent absenteeism_days
## Min. :0.000 Min. : 0.00 Min. : 0.000
## 1st Qu.:1.000 1st Qu.: 8.15 1st Qu.: 3.000
## Median :3.000 Median :15.90 Median : 6.000
## Mean :2.828 Mean :15.99 Mean : 5.524
## 3rd Qu.:4.000 3rd Qu.:22.98 3rd Qu.: 8.000
## Max. :8.000 Max. :44.20 Max. :14.000
##
## internet_speed_mbps screen_time_total_hours behavioral_cluster addiction_score
## Min. : 5.00 Min. : 1.20 Length :250 Min. :12.28
## 1st Qu.: 61.38 1st Qu.: 6.20 N.unique : 7 1st Qu.:29.88
## Median : 99.15 Median : 8.20 N.blank : 0 Median :39.88
## Mean : 99.25 Mean : 8.24 Min.nchar: 12 Mean :38.74
## 3rd Qu.:133.57 3rd Qu.:10.50 Max.nchar: 19 3rd Qu.:47.11
## Max. :255.50 Max. :15.10 Max. :68.00
##
## addiction_binary addiction_severity burnout_probability
## Min. :0.000 Length :250 Min. :0.3200
## 1st Qu.:0.000 N.unique : 4 1st Qu.:1.0000
## Median :0.000 N.blank : 0 Median :1.0000
## Mean :0.168 Min.nchar: 4 Mean :0.9969
## 3rd Qu.:0.000 Max.nchar: 8 3rd Qu.:1.0000
## Max. :1.000 Max. :1.0000
##
## mental_health_risk_score churn_probability
## Min. :0.1200 Min. :0.1500
## 1st Qu.:0.4062 1st Qu.:0.7322
## Median :0.5150 Median :0.8080
## Mean :0.5096 Mean :0.7956
## 3rd Qu.:0.6000 3rd Qu.:0.8780
## Max. :0.9200 Max. :1.0000
##
mygamingfile$gender <- factor(mygamingfile$gender)
summary(mygamingfile)
## user_id age gender country
## Length :250 Min. :13.00 Female : 66 Length :250
## N.unique :250 1st Qu.:18.00 Male :158 N.unique : 15
## N.blank : 0 Median :22.00 Non-binary : 18 N.blank : 0
## Min.nchar: 9 Mean :22.16 Prefer not to say: 8 Min.nchar: 2
## Max.nchar: 9 3rd Qu.:27.00 Max.nchar: 11
## Max. :40.00
##
## occupation income_level years_gaming preferred_genre
## Length :250 Length :250 Min. : 1.000 Length :250
## N.unique : 5 N.unique : 5 1st Qu.: 6.000 N.unique : 10
## N.blank : 0 N.blank : 0 Median : 9.000 N.blank : 0
## Min.nchar: 7 Min.nchar: 3 Mean : 9.668 Min.nchar: 3
## Max.nchar: 24 Max.nchar: 12 3rd Qu.:14.750 Max.nchar: 13
## Max. :25.000
##
## platform device_type rank_tier daily_playtime_hours
## Length :250 Length :250 Length :250 Min. : 0.500
## N.unique : 5 N.unique : 6 N.unique : 8 1st Qu.: 4.225
## N.blank : 0 N.blank : 0 N.blank : 0 Median : 6.450
## Min.nchar: 2 Min.nchar: 5 Min.nchar: 4 Mean : 6.153
## Max.nchar: 10 Max.nchar: 12 Max.nchar: 11 3rd Qu.: 8.175
## Max. :11.900
##
## weekly_play_sessions late_night_sessions_hours weekend_playtime_hours
## Min. : 1.000 Min. :0.000 Min. : 0.500
## 1st Qu.: 4.000 1st Qu.:1.125 1st Qu.: 5.600
## Median : 7.000 Median :2.100 Median : 8.150
## Mean : 7.056 Mean :2.102 Mean : 8.368
## 3rd Qu.:10.000 3rd Qu.:3.000 3rd Qu.:10.850
## Max. :15.000 Max. :5.200 Max. :20.000
##
## consecutive_hours_max multiplayer_ratio toxic_chat_reports rage_quit_frequency
## Min. : 1.000 Min. :0.0000 Min. : 0.000 Min. : 0.000
## 1st Qu.: 5.525 1st Qu.:0.3000 1st Qu.: 0.000 1st Qu.: 0.000
## Median :10.100 Median :0.4500 Median : 1.000 Median : 1.000
## Mean : 9.715 Mean :0.4622 Mean : 2.948 Mean : 1.896
## 3rd Qu.:13.175 3rd Qu.:0.6300 3rd Qu.: 2.000 3rd Qu.: 3.000
## Max. :20.600 Max. :1.0000 Max. :32.000 Max. :10.000
##
## in_game_purchases monthly_spending_usd lootbox_openings subscription_status
## Min. : 0.000 Min. : 0.00 Min. : 0.000 Length :250
## 1st Qu.: 0.000 1st Qu.: 15.91 1st Qu.: 3.000 N.unique : 4
## Median : 3.000 Median : 35.71 Median : 7.000 N.blank : 0
## Mean : 4.072 Mean : 41.12 Mean : 8.468 Min.nchar: 4
## 3rd Qu.: 7.000 3rd Qu.: 57.72 3rd Qu.:12.000 Max.nchar: 8
## Max. :21.000 Max. :182.60 Max. :41.000
##
## stress_score loneliness_score dopamine_dependency_index self_control_score
## Min. : 1.000 Min. : 1.00 Min. :1.000 Min. : 1.000
## 1st Qu.: 5.700 1st Qu.: 3.70 1st Qu.:2.925 1st Qu.: 5.100
## Median : 6.950 Median : 4.90 Median :4.400 Median : 6.500
## Mean : 6.819 Mean : 5.06 Mean :4.312 Mean : 6.463
## 3rd Qu.: 8.000 3rd Qu.: 6.50 3rd Qu.:5.675 3rd Qu.: 7.900
## Max. :10.000 Max. :10.00 Max. :8.600 Max. :10.000
##
## impulsiveness_score anxiety_level depression_indicator emotional_stability
## Min. : 1.000 Min. : 1.000 Min. :1.000 Min. : 2.300
## 1st Qu.: 3.700 1st Qu.: 4.425 1st Qu.:3.500 1st Qu.: 5.300
## Median : 5.000 Median : 5.600 Median :4.500 Median : 6.600
## Mean : 4.908 Mean : 5.608 Mean :4.611 Mean : 6.496
## 3rd Qu.: 6.300 3rd Qu.: 6.675 3rd Qu.:5.900 3rd Qu.: 7.600
## Max. :10.000 Max. :10.000 Max. :8.600 Max. :10.000
## NAs :11
## sleep_hours exercise_frequency_per_week caffeine_intake_cups_day
## Min. :3.400 Min. :0.000 Min. :0.000
## 1st Qu.:6.100 1st Qu.:0.000 1st Qu.:1.000
## Median :6.800 Median :1.000 Median :2.000
## Mean :6.766 Mean :1.392 Mean :2.456
## 3rd Qu.:7.700 3rd Qu.:2.000 3rd Qu.:4.000
## Max. :9.500 Max. :5.000 Max. :7.000
##
## social_interaction_hours relationship_status gpa_or_performance_score
## Min. :0.000 Length :250 Min. :2.170
## 1st Qu.:1.000 N.unique : 5 1st Qu.:3.478
## Median :2.000 N.blank : 0 Median :4.000
## Mean :2.139 Min.nchar: 6 Mean :3.732
## 3rd Qu.:3.300 Max.nchar: 17 3rd Qu.:4.000
## Max. :6.600 Max. :4.000
## NAs :10
## missed_deadlines productivity_drop_percent absenteeism_days
## Min. :0.000 Min. : 0.00 Min. : 0.000
## 1st Qu.:1.000 1st Qu.: 8.15 1st Qu.: 3.000
## Median :3.000 Median :15.90 Median : 6.000
## Mean :2.828 Mean :15.99 Mean : 5.524
## 3rd Qu.:4.000 3rd Qu.:22.98 3rd Qu.: 8.000
## Max. :8.000 Max. :44.20 Max. :14.000
##
## internet_speed_mbps screen_time_total_hours behavioral_cluster addiction_score
## Min. : 5.00 Min. : 1.20 Length :250 Min. :12.28
## 1st Qu.: 61.38 1st Qu.: 6.20 N.unique : 7 1st Qu.:29.88
## Median : 99.15 Median : 8.20 N.blank : 0 Median :39.88
## Mean : 99.25 Mean : 8.24 Min.nchar: 12 Mean :38.74
## 3rd Qu.:133.57 3rd Qu.:10.50 Max.nchar: 19 3rd Qu.:47.11
## Max. :255.50 Max. :15.10 Max. :68.00
##
## addiction_binary addiction_severity burnout_probability
## Min. :0.000 Length :250 Min. :0.3200
## 1st Qu.:0.000 N.unique : 4 1st Qu.:1.0000
## Median :0.000 N.blank : 0 Median :1.0000
## Mean :0.168 Min.nchar: 4 Mean :0.9969
## 3rd Qu.:0.000 Max.nchar: 8 3rd Qu.:1.0000
## Max. :1.000 Max. :1.0000
##
## mental_health_risk_score churn_probability
## Min. :0.1200 Min. :0.1500
## 1st Qu.:0.4062 1st Qu.:0.7322
## Median :0.5150 Median :0.8080
## Mean :0.5096 Mean :0.7956
## 3rd Qu.:0.6000 3rd Qu.:0.8780
## Max. :0.9200 Max. :1.0000
##
mygamingfile$country <- factor(mygamingfile$country)
mygamingfile$occupation <- factor(mygamingfile$occupation)
mygamingfile$user_id <- factor(mygamingfile$user_id)
mygamingfile[sapply(mygamingfile,FUN=is.character)]
## # A tibble: 250 × 9
## income_level preferred_genre platform device_type rank_tier
## <chr> <chr> <chr> <chr> <chr>
## 1 Middle Sandbox PC Laptop Gold
## 2 Lower-Middle RPG Mobile Mixed Bronze
## 3 Middle RPG PC+Mobile High-end PC Master
## 4 Upper-Middle Strategy PC+Mobile Mobile Bronze
## 5 Middle Strategy PC Laptop Bronze
## 6 Middle Horror PC Mobile Silver
## 7 Lower-Middle RPG Console Console Silver
## 8 Middle MOBA PC Mixed Bronze
## 9 High Sports Mobile Mixed Gold
## 10 Middle Strategy Console Mid-range PC Gold
## # ℹ 240 more rows
## # ℹ 4 more variables: subscription_status <chr>, relationship_status <chr>,
## # behavioral_cluster <chr>, addiction_severity <chr>
mygamingfile[sapply(mygamingfile,FUN=is.character)]<- lapply(mygamingfile[sapply(mygamingfile,FUN=is.character)],as.factor)
gapminder
## # A tibble: 1,704 × 6
## country continent year lifeExp pop gdpPercap
## <fct> <fct> <int> <dbl> <int> <dbl>
## 1 Afghanistan Asia 1952 28.8 8425333 779.
## 2 Afghanistan Asia 1957 30.3 9240934 821.
## 3 Afghanistan Asia 1962 32.0 10267083 853.
## 4 Afghanistan Asia 1967 34.0 11537966 836.
## 5 Afghanistan Asia 1972 36.1 13079460 740.
## 6 Afghanistan Asia 1977 38.4 14880372 786.
## 7 Afghanistan Asia 1982 39.9 12881816 978.
## 8 Afghanistan Asia 1987 40.8 13867957 852.
## 9 Afghanistan Asia 1992 41.7 16317921 649.
## 10 Afghanistan Asia 1997 41.8 22227415 635.
## # ℹ 1,694 more rows
gapminder %>% filter(continent == "Africa" & year < 2000 & year > 1960) %>% arrange(desc(pop)) %>% arrange(gdpPercap, lifeExp, year)
## # A tibble: 416 × 6
## country continent year lifeExp pop gdpPercap
## <fct> <fct> <int> <dbl> <int> <dbl>
## 1 Congo, Dem. Rep. Africa 1997 42.6 47798986 312.
## 2 Burundi Africa 1962 42.0 2961915 355.
## 3 Eritrea Africa 1962 40.2 1666618 381.
## 4 Mozambique Africa 1987 42.9 12891952 390.
## 5 Mozambique Africa 1992 44.3 13160731 411.
## 6 Lesotho Africa 1962 47.7 893143 412.
## 7 Burundi Africa 1967 43.5 3330989 413.
## 8 Ethiopia Africa 1962 40.1 25145372 419.
## 9 Ethiopia Africa 1992 48.1 52088559 421.
## 10 Malawi Africa 1962 38.4 3628608 428.
## # ℹ 406 more rows
The mutate verb
Using mutate to change or create a column
# Use mutate to change lifeExp to be in months
gapminder %>% mutate (lifeExp = lifeExp * 12)
## # A tibble: 1,704 × 6
## country continent year lifeExp pop gdpPercap
## <fct> <fct> <int> <dbl> <int> <dbl>
## 1 Afghanistan Asia 1952 346. 8425333 779.
## 2 Afghanistan Asia 1957 364. 9240934 821.
## 3 Afghanistan Asia 1962 384. 10267083 853.
## 4 Afghanistan Asia 1967 408. 11537966 836.
## 5 Afghanistan Asia 1972 433. 13079460 740.
## 6 Afghanistan Asia 1977 461. 14880372 786.
## 7 Afghanistan Asia 1982 478. 12881816 978.
## 8 Afghanistan Asia 1987 490. 13867957 852.
## 9 Afghanistan Asia 1992 500. 16317921 649.
## 10 Afghanistan Asia 1997 501. 22227415 635.
## # ℹ 1,694 more rows
# Use mutate to create a new column called lifeExpMonths
gapminder1 <- gapminder %>% mutate (lifeExpMonths
= lifeExp * 12)
gapminder1
## # A tibble: 1,704 × 7
## country continent year lifeExp pop gdpPercap lifeExpMonths
## <fct> <fct> <int> <dbl> <int> <dbl> <dbl>
## 1 Afghanistan Asia 1952 28.8 8425333 779. 346.
## 2 Afghanistan Asia 1957 30.3 9240934 821. 364.
## 3 Afghanistan Asia 1962 32.0 10267083 853. 384.
## 4 Afghanistan Asia 1967 34.0 11537966 836. 408.
## 5 Afghanistan Asia 1972 36.1 13079460 740. 433.
## 6 Afghanistan Asia 1977 38.4 14880372 786. 461.
## 7 Afghanistan Asia 1982 39.9 12881816 978. 478.
## 8 Afghanistan Asia 1987 40.8 13867957 852. 490.
## 9 Afghanistan Asia 1992 41.7 16317921 649. 500.
## 10 Afghanistan Asia 1997 41.8 22227415 635. 501.
## # ℹ 1,694 more rows
Combining filter, mutate, and arrange
# Filter, mutate, and arrange the gapminder dataset
gapminder %>% filter(year == 2007) %>% mutate(lifeExpMonths = 12 * lifeExp) %>% arrange(desc(lifeExpMonths))
## # A tibble: 142 × 7
## country continent year lifeExp pop gdpPercap lifeExpMonths
## <fct> <fct> <int> <dbl> <int> <dbl> <dbl>
## 1 Japan Asia 2007 82.6 127467972 31656. 991.
## 2 Hong Kong, China Asia 2007 82.2 6980412 39725. 986.
## 3 Iceland Europe 2007 81.8 301931 36181. 981.
## 4 Switzerland Europe 2007 81.7 7554661 37506. 980.
## 5 Australia Oceania 2007 81.2 20434176 34435. 975.
## 6 Spain Europe 2007 80.9 40448191 28821. 971.
## 7 Sweden Europe 2007 80.9 9031088 33860. 971.
## 8 Israel Asia 2007 80.7 6426679 25523. 969.
## 9 France Europe 2007 80.7 61083916 30470. 968.
## 10 Canada Americas 2007 80.7 33390141 36319. 968.
## # ℹ 132 more rows
colnames(gapminder)
## [1] "country" "continent" "year" "lifeExp" "pop" "gdpPercap"
summary(gapminder)
## country continent year lifeExp
## Afghanistan: 12 Africa :624 Min. :1952 Min. :23.60
## Albania : 12 Americas:300 1st Qu.:1966 1st Qu.:48.20
## Algeria : 12 Asia :396 Median :1980 Median :60.71
## Angola : 12 Europe :360 Mean :1980 Mean :59.47
## Argentina : 12 Oceania : 24 3rd Qu.:1993 3rd Qu.:70.85
## Australia : 12 Max. :2007 Max. :82.60
## (Other) :1632
## pop gdpPercap
## Min. :6.001e+04 Min. : 241.2
## 1st Qu.:2.794e+06 1st Qu.: 1202.1
## Median :7.024e+06 Median : 3531.8
## Mean :2.960e+07 Mean : 7215.3
## 3rd Qu.:1.959e+07 3rd Qu.: 9325.5
## Max. :1.319e+09 Max. :113523.1
##
colnames(gapminder) <- c("country","Continent","Year", "LifeExp", "Population", "GdpPerCap")
# Load the ggplot2 package as well
library(ggplot2)
# Create gapminder_1952
gapminder
## # A tibble: 1,704 × 6
## country Continent Year LifeExp Population GdpPerCap
## <fct> <fct> <int> <dbl> <int> <dbl>
## 1 Afghanistan Asia 1952 28.8 8425333 779.
## 2 Afghanistan Asia 1957 30.3 9240934 821.
## 3 Afghanistan Asia 1962 32.0 10267083 853.
## 4 Afghanistan Asia 1967 34.0 11537966 836.
## 5 Afghanistan Asia 1972 36.1 13079460 740.
## 6 Afghanistan Asia 1977 38.4 14880372 786.
## 7 Afghanistan Asia 1982 39.9 12881816 978.
## 8 Afghanistan Asia 1987 40.8 13867957 852.
## 9 Afghanistan Asia 1992 41.7 16317921 649.
## 10 Afghanistan Asia 1997 41.8 22227415 635.
## # ℹ 1,694 more rows
gapminder_1952 <- gapminder %>% filter(Year == 1952)
gapminder_1952
## # A tibble: 142 × 6
## country Continent Year LifeExp Population GdpPerCap
## <fct> <fct> <int> <dbl> <int> <dbl>
## 1 Afghanistan Asia 1952 28.8 8425333 779.
## 2 Albania Europe 1952 55.2 1282697 1601.
## 3 Algeria Africa 1952 43.1 9279525 2449.
## 4 Angola Africa 1952 30.0 4232095 3521.
## 5 Argentina Americas 1952 62.5 17876956 5911.
## 6 Australia Oceania 1952 69.1 8691212 10040.
## 7 Austria Europe 1952 66.8 6927772 6137.
## 8 Bahrain Asia 1952 50.9 120447 9867.
## 9 Bangladesh Asia 1952 37.5 46886859 684.
## 10 Belgium Europe 1952 68 8730405 8343.
## # ℹ 132 more rows
colnames(gapminder_1952) <- colnames(gapminder1)
# Create a scatter plot with pop on the x-axis and gdpPercap on the y-axis
ggplot(gapminder_1952, aes(x = pop, y = gdpPercap)) +
geom_point()

# Create a scatter plot with pop on the x-axis and lifeExp on the y-axis
ggplot(gapminder_1952, aes(x = pop, y= lifeExp))+ geom_point()

# Scatter plot comparing pop and lifeExp, with x-axis on a log scale
ggplot(gapminder_1952, aes(x = pop, y = lifeExp)) +
geom_point() + scale_x_log10()

# Scatter plot comparing pop and gdpPercap, with both axes on a log scale
ggplot(gapminder_1952, aes(x = pop, y = gdpPercap))+ geom_point() + scale_x_log10() + scale_y_log10()

# Scatter plot comparing pop and lifeExp, with color representing continent
ggplot(gapminder_1952, aes(x = pop, y = lifeExp, color = continent))+
geom_point()+
scale_x_log10()

# Add the size aesthetic to represent a country's gdpPercap
ggplot(gapminder_1952, aes(x = pop, y = lifeExp, color = continent, size = gdpPercap, shape = continent)) +
geom_point() +
scale_x_log10()

# Scatter plot comparing pop and lifeExp, faceted by continent
ggplot(gapminder_1952, aes(x = pop, y = lifeExp))+ geom_point()+
scale_x_log10() + facet_wrap(~ continent)

# Summarize to find the median life expectancy
gapminder %>% filter(Year == 1992) %>% summarize(medianLifeExp = median(LifeExp), AvgLifeExp = mean(LifeExp), maxLifeExp = max(LifeExp), minLifeExp = min(LifeExp))
## # A tibble: 1 × 4
## medianLifeExp AvgLifeExp maxLifeExp minLifeExp
## <dbl> <dbl> <dbl> <dbl>
## 1 67.7 64.2 79.4 23.6
gapminder %>% filter (LifeExp == 79.36 & Year == 1992)
## # A tibble: 1 × 6
## country Continent Year LifeExp Population GdpPerCap
## <fct> <fct> <int> <dbl> <int> <dbl>
## 1 Japan Asia 1992 79.4 124329269 26825.
# Filter for 1957 then summarize the median life expectancy
gapminder %>% filter(Year == 1957) %>% summarize(medianLifeExp = median(LifeExp))
## # A tibble: 1 × 1
## medianLifeExp
## <dbl>
## 1 48.4
# Filter for 1957 then summarize the median life expectancy and the maximum GDP per capita
gapminder %>% filter(Year == 1957) %>% summarize(medianLifeExp = median(LifeExp), maxGdpPercap = max(GdpPerCap))
## # A tibble: 1 × 2
## medianLifeExp maxGdpPercap
## <dbl> <dbl>
## 1 48.4 113523.
# Find median life expectancy and maximum GDP per capita in each year
gapminder %>% group_by(Year) %>% summarize(medianLifeExp = median(LifeExp), maxGdpPercap = max(GdpPerCap))
## # A tibble: 12 × 3
## Year medianLifeExp maxGdpPercap
## <int> <dbl> <dbl>
## 1 1952 45.1 108382.
## 2 1957 48.4 113523.
## 3 1962 50.9 95458.
## 4 1967 53.8 80895.
## 5 1972 56.5 109348.
## 6 1977 59.7 59265.
## 7 1982 62.4 33693.
## 8 1987 65.8 31541.
## 9 1992 67.7 34933.
## 10 1997 69.4 41283.
## 11 2002 70.8 44684.
## 12 2007 71.9 49357.
# Find median life expectancy and maximum GDP per capita in each continent in 1957
gapminder %>% filter(Year == 1957) %>% group_by(Continent) %>% summarize(medianLifeExp = median(LifeExp), maxGdpPercap = max(GdpPerCap))
## # A tibble: 5 × 3
## Continent medianLifeExp maxGdpPercap
## <fct> <dbl> <dbl>
## 1 Africa 40.6 5487.
## 2 Americas 56.1 14847.
## 3 Asia 48.3 113523.
## 4 Europe 67.6 17909.
## 5 Oceania 70.3 12247.
# Find median life expectancy and maximum GDP per capita in each continent/year combination
gapminder%>% group_by(Year,Continent) %>% summarize(medianLifeExp = median(LifeExp), maxGdpPercap = max(GdpPerCap))
## `summarise()` has regrouped the output.
## ℹ Summaries were computed grouped by Year and Continent.
## ℹ Output is grouped by Year.
## ℹ Use `summarise(.groups = "drop_last")` to silence this message.
## ℹ Use `summarise(.by = c(Year, Continent))` for per-operation grouping
## (`?dplyr::dplyr_by`) instead.
## # A tibble: 60 × 4
## # Groups: Year [12]
## Year Continent medianLifeExp maxGdpPercap
## <int> <fct> <dbl> <dbl>
## 1 1952 Africa 38.8 4725.
## 2 1952 Americas 54.7 13990.
## 3 1952 Asia 44.9 108382.
## 4 1952 Europe 65.9 14734.
## 5 1952 Oceania 69.3 10557.
## 6 1957 Africa 40.6 5487.
## 7 1957 Americas 56.1 14847.
## 8 1957 Asia 48.3 113523.
## 9 1957 Europe 67.6 17909.
## 10 1957 Oceania 70.3 12247.
## # ℹ 50 more rows
gapminder %>% group_by(Continent,Year) %>% summarize(medianLifeExp = median(LifeExp), maxGdpPercap = max(GdpPerCap))
## `summarise()` has regrouped the output.
## ℹ Summaries were computed grouped by Continent and Year.
## ℹ Output is grouped by Continent.
## ℹ Use `summarise(.groups = "drop_last")` to silence this message.
## ℹ Use `summarise(.by = c(Continent, Year))` for per-operation grouping
## (`?dplyr::dplyr_by`) instead.
## # A tibble: 60 × 4
## # Groups: Continent [5]
## Continent Year medianLifeExp maxGdpPercap
## <fct> <int> <dbl> <dbl>
## 1 Africa 1952 38.8 4725.
## 2 Africa 1957 40.6 5487.
## 3 Africa 1962 42.6 6757.
## 4 Africa 1967 44.7 18773.
## 5 Africa 1972 47.0 21011.
## 6 Africa 1977 49.3 21951.
## 7 Africa 1982 50.8 17364.
## 8 Africa 1987 51.6 11864.
## 9 Africa 1992 52.4 13522.
## 10 Africa 1997 52.8 14723.
## # ℹ 50 more rows
by_year <- gapminder %>%
group_by(Year) %>%
summarize(medianLifeExp = median(LifeExp),
maxGdpPercap = max(GdpPerCap))
# Create a scatter plot showing the change in medianLifeExp over time
ggplot(by_year, aes(x = Year, y = medianLifeExp))+ geom_point()+ expand_limits(y =0)

# Summarize medianGdpPercap within each continent within each year: by_year_continent
by_year_continent <- gapminder %>%
group_by(Continent, Year) %>%
summarize(medianGdpPercap = median(GdpPerCap))
## `summarise()` has regrouped the output.
## ℹ Summaries were computed grouped by Continent and Year.
## ℹ Output is grouped by Continent.
## ℹ Use `summarise(.groups = "drop_last")` to silence this message.
## ℹ Use `summarise(.by = c(Continent, Year))` for per-operation grouping
## (`?dplyr::dplyr_by`) instead.
# Plot the change in medianGdpPercap in each continent over time
ggplot(by_year_continent, aes(x = Year, y = medianGdpPercap, color = Continent))+ geom_point()+ expand_limits(y =0)

# Summarize the median GDP and median life expectancy per continent in 2007
by_continent_2007_avg <- gapminder %>% filter (Year == 2007) %>% group_by(Continent) %>% summarize(medianLifeExp = median(LifeExp), medianGdpPercap = median(GdpPerCap), AvgPop = mean(Population))
by_continent_2007_med <- gapminder %>% filter (Year == 2007) %>% group_by(Continent) %>% summarize(medianLifeExp = median(LifeExp), medianGdpPercap = median(GdpPerCap), medianPop = median(Population))
by_continent_2007_avg
## # A tibble: 5 × 4
## Continent medianLifeExp medianGdpPercap AvgPop
## <fct> <dbl> <dbl> <dbl>
## 1 Africa 52.9 1452. 17875763.
## 2 Americas 72.9 8948. 35954847.
## 3 Asia 72.4 4471. 115513752.
## 4 Europe 78.6 28054. 19536618.
## 5 Oceania 80.7 29810. 12274974.
by_continent_2007_med
## # A tibble: 5 × 4
## Continent medianLifeExp medianGdpPercap medianPop
## <fct> <dbl> <dbl> <dbl>
## 1 Africa 52.9 1452. 10093310.
## 2 Americas 72.9 8948. 9319622
## 3 Asia 72.4 4471. 24821286
## 4 Europe 78.6 28054. 9493598
## 5 Oceania 80.7 29810. 12274974.
# Summarize the median gdpPercap by year, then save it as by_year
by_year <- gapminder %>%group_by(Year) %>% summarize(medianGdpPercap = median(GdpPerCap))
# Create a line plot showing the change in medianGdpPercap over time
ggplot(by_year, aes(x = Year, y = medianGdpPercap))+ geom_line() + expand_limits(y = 0)

Visualizing GDP per capita by country in Oceania
# Filter for observations in the Oceania continent in 1952
oceania_1952 <- gapminder %>% filter(Continent == "Oceania", Year == 1952)
# Create a bar plot of gdpPercap by country
ggplot(oceania_1952, aes(x = country, y = GdpPerCap))+ geom_col()

gapminder_1952 <- gapminder %>%
filter(Year == 1952) %>%
mutate(pop_by_mil =Population/ 1000000)
# Create a histogram of population (pop_by_mil)
ggplot(gapminder_1952, aes(x =pop_by_mil))+ geom_histogram(bins = 50)

gapminder_1952 <- gapminder %>%
filter(Year == 1952)
# Create a histogram of population (pop), with x on a log scale
ggplot(gapminder_1952, aes(x = Population))+ geom_histogram()+ scale_x_log10()
## `stat_bin()` using `bins = 30`. Pick better value `binwidth`.

gapminder_1952 <- gapminder %>%
filter(Year == 1952)
# Create a boxplot comparing gdpPercap among continents
ggplot(gapminder_1952, aes(x = Continent, y = GdpPerCap))+ geom_boxplot()+ scale_y_log10()

gapminder_1952 <- gapminder %>%
filter(Year == 1952)
# Add a title to this graph: "Comparing GDP per capita across continents"
ggplot(gapminder_1952, aes(x = Continent, y = GdpPerCap)) +
geom_boxplot() + labs(title = "Comparing GDP per capita across continents")+
scale_y_log10()
