# Load required packages
library(readxl)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
# Step 1: Load the dataset
countries_data <- read.csv("C:/Users/manja/Downloads/countries.csv")

# Step 2: Filter countries with 'High income'
# Filter high-income countries based on GDP per capita
high_income_countries <- subset(countries_data, `GDP....per.capita.` > 50000)

# View the resulting high-income countries
print(high_income_countries)
##         Country                              Region Population Area..sq..mi..
## 122 Luxembourg  WESTERN EUROPE                          474413           2586
##     Pop..Density..per.sq..mi.. Coastline..coast.area.ratio. Net.migration
## 122                      183,5                         0,00          8,97
##     Infant.mortality..per.1000.births. GDP....per.capita. Literacy....
## 122                               4,81              55100        100,0
##     Phones..per.1000. Arable.... Crops.... Other.... Climate Birthrate
## 122             515,4      23,28       0,4     76,32             11,94
##     Deathrate Agriculture Industry Service
## 122      8,41        0,01     0,13    0,86
# Step 3: Filter countries in 'Europe' or 'Americas' with life expectancy > 80
# Filter countries in 'Europe' or 'Americas' with life expectancy greater than 80
filtered_countries <- subset(countries_data, (Region == "Europe" | Region == "Americas") & `Infant.mortality..per.1000.births.` < 80)

# View the resulting filtered countries
print(filtered_countries)
##  [1] Country                            Region                            
##  [3] Population                         Area..sq..mi..                    
##  [5] Pop..Density..per.sq..mi..         Coastline..coast.area.ratio.      
##  [7] Net.migration                      Infant.mortality..per.1000.births.
##  [9] GDP....per.capita.                 Literacy....                      
## [11] Phones..per.1000.                  Arable....                        
## [13] Crops....                          Other....                         
## [15] Climate                            Birthrate                         
## [17] Deathrate                          Agriculture                       
## [19] Industry                           Service                           
## <0 rows> (or 0-length row.names)
# Step 4: Filter top 5 countries based on GDP growth
# Filter the top 5 countries based on GDP growth
top_5_countries <- countries_data %>% top_n(5, `GDP....per.capita.`)

# View the resulting top 5 countries
print(top_5_countries)
##           Country                              Region Population Area..sq..mi..
## 1        Bermuda  NORTHERN AMERICA                         65773             53
## 2 Cayman Islands              LATIN AMER. & CARIB          45436            262
## 3     Luxembourg  WESTERN EUROPE                          474413           2586
## 4         Norway  WESTERN EUROPE                         4610820         323802
## 5  United States  NORTHERN AMERICA                     298444215        9631420
##   Pop..Density..per.sq..mi.. Coastline..coast.area.ratio. Net.migration
## 1                     1241,0                       194,34          2,49
## 2                      173,4                        61,07         18,75
## 3                      183,5                         0,00          8,97
## 4                       14,2                         7,77          1,74
## 5                       31,0                         0,21          3,41
##   Infant.mortality..per.1000.births. GDP....per.capita. Literacy....
## 1                               8,53              36000         98,0
## 2                               8,19              35000         98,0
## 3                               4,81              55100        100,0
## 4                                3,7              37800        100,0
## 5                                6,5              37800         97,0
##   Phones..per.1000. Arable.... Crops.... Other.... Climate Birthrate Deathrate
## 1             851,4         20         0        80       2      11,4      7,74
## 2             836,3       3,85         0     96,15       2     12,74      4,89
## 3             515,4      23,28       0,4     76,32             11,94      8,41
## 4             461,7       2,87         0     97,13       3     11,46       9,4
## 5             898,0      19,13      0,22     80,65       3     14,14      8,26
##   Agriculture Industry Service
## 1        0,01      0,1    0,89
## 2       0,014    0,032   0,954
## 3        0,01     0,13    0,86
## 4       0,021    0,415   0,564
## 5        0,01    0,204   0,787
# Step 5: Create the 'NED' variable
countries_data$NED <- ifelse(countries_data$Country == "Netherlands", 1, 0)

# Step 6: Select and arrange the columns
selected_columns <- select(countries_data, Country, NED)
arranged_data <- arrange(selected_columns, desc(NED))
# View the column names of the dataset
colnames(countries_data)
##  [1] "Country"                            "Region"                            
##  [3] "Population"                         "Area..sq..mi.."                    
##  [5] "Pop..Density..per.sq..mi.."         "Coastline..coast.area.ratio."      
##  [7] "Net.migration"                      "Infant.mortality..per.1000.births."
##  [9] "GDP....per.capita."                 "Literacy...."                      
## [11] "Phones..per.1000."                  "Arable...."                        
## [13] "Crops...."                          "Other...."                         
## [15] "Climate"                            "Birthrate"                         
## [17] "Deathrate"                          "Agriculture"                       
## [19] "Industry"                           "Service"                           
## [21] "NED"
# Load necessary libraries
library(readxl)
library(dplyr)
library(tidyr)

# Read the dataset
countries_data <- read.csv("C:/Users/manja/Downloads/countries.csv")

# Filter for income level equal to "Lower middle income"
filtered_data <- countries_data %>%
                  filter(GDP....per.capita. == "Lower middle income") %>%
                  group_by(Region) %>%
                  summarise(Unemployment_Median = median(Service, na.rm = TRUE),
                            Number_of_Countries = n())

# Sort the results from the highest median unemployment downward
sorted_data <- filtered_data %>%
                arrange(desc(Unemployment_Median))

# View the sorted data
print(sorted_data)
## # A tibble: 0 × 3
## # ℹ 3 variables: Region <chr>, Unemployment_Median <chr>,
## #   Number_of_Countries <int>
hprice <- read.csv("C:/Users/manja/Downloads/hprice.csv")
library(dplyr)
filtered_hprice <- hprice %>% filter(Price > 9999)
library(tidyr)
pivot_hprice <- filtered_hprice %>%
    group_by(Brick, Neighborhood) %>%
    summarise(
        Price.avg = mean(Price),
        SqFt.avg = mean(SqFt),
        Price.per.SqFt = mean(Price/SqFt)
    )
## `summarise()` has grouped output by 'Brick'. You can override using the
## `.groups` argument.
library(knitr)
library(kableExtra)
## 
## Attaching package: 'kableExtra'
## 
## The following object is masked from 'package:dplyr':
## 
##     group_rows
kable(pivot_hprice, "html") %>%
    kable_styling("striped", full_width = F) 
Brick Neighborhood Price.avg SqFt.avg Price.per.SqFt
No East 117750.0 2001.538 59.01310
No North 108583.8 1928.108 56.42026
No West 148230.4 2073.478 71.88587
Yes East 135468.4 2031.053 66.80893
Yes North 118457.1 1857.143 64.27986
Yes West 175200.0 2091.250 83.85290