For this Homework assignment, I will be using the wvs_justifbribe data set. A data set on attitudes about the justifiability of bribe-taking for all observations in the third to sixth wave of the World Values Survey.
df <- read.csv("justifbribe.csv")
head(df)
#Summary
summary(df)
## X s002 s003 country
## Min. : 1 Min. :1.000 Min. : 8.0 Length:348532
## 1st Qu.: 87134 1st Qu.:3.000 1st Qu.:246.0 Class :character
## Median :174266 Median :4.000 Median :466.0 Mode :character
## Mean :174266 Mean :4.274 Mean :465.6
## 3rd Qu.:261399 3rd Qu.:6.000 3rd Qu.:710.0
## Max. :348532 Max. :6.000 Max. :914.0
##
## s020 uid f117
## Min. :1981 Min. : 1 Min. : 1.00
## 1st Qu.:1996 1st Qu.: 87134 1st Qu.: 1.00
## Median :2004 Median :174266 Median : 1.00
## Mean :2003 Mean :174266 Mean : 1.82
## 3rd Qu.:2010 3rd Qu.:261399 3rd Qu.: 2.00
## Max. :2016 Max. :348532 Max. :10.00
## NA's :15532
print("Information for s020: ")
## [1] "Information for s020: "
print(paste(" Mean = ",mean(df$s020, na.rm = TRUE)))
## [1] " Mean = 2002.52873480771"
print(paste(" Median = ",median(df$s020, na.rm = TRUE) ))
## [1] " Median = 2004"
print("Information for f117: ")
## [1] "Information for f117: "
print(paste(" Mean = ",mean(df$f117, na.rm = TRUE)))
## [1] " Mean = 1.81966366366366"
print(paste(" Median = ",median(df$f117, na.rm = TRUE) ))
## [1] " Median = 1"
#Columns
my_df <-subset(df, select = c("country","s020","f117"))
#Rows
my_df <- my_df[my_df$s020 > 2010,]
head(my_df)
names(my_df) <- c("country","year","tolerance_score")
The information changed for the year because I only left out survey results from 2010 and onward. The mean of the tolerance score has increased a bit from it’s previous value, I am not sure why yet.
#Summary
summary(my_df)
## country year tolerance_score
## Length:83863 Min. :2011 Min. : 1.000
## Class :character 1st Qu.:2011 1st Qu.: 1.000
## Mode :character Median :2012 Median : 1.000
## Mean :2012 Mean : 1.992
## 3rd Qu.:2013 3rd Qu.: 2.000
## Max. :2016 Max. :10.000
## NA's :1621
print("Information for year: ")
## [1] "Information for year: "
print(paste(" Mean = ",mean(my_df$year, na.rm = TRUE)))
## [1] " Mean = 2012.25678785638"
print(paste(" Median = ",median(my_df$year, na.rm = TRUE) ))
## [1] " Median = 2012"
print("Information for tolerance score: ")
## [1] "Information for tolerance score: "
print(paste(" Mean = ",mean(my_df$tolerance_score, na.rm = TRUE)))
## [1] " Mean = 1.99224240655626"
print(paste(" Median = ",median(my_df$tolerance_score, na.rm = TRUE) ))
## [1] " Median = 1"
my_df$tolerance_score[my_df$tolerance_score == 1] <- "never"
my_df$tolerance_score[my_df$tolerance_score == 10] <- "always"
my_df$tolerance_score[my_df$tolerance_score == 5] <- "neutral"
head(my_df[sample(nrow(my_df)), ])
github_csv_url <- "https://raw.githubusercontent.com/Raharijao/CUNYSPS_SummerBridgeProgram_2023/main/justifbribe.csv"
# Read the CSV file from GitHub
data <- read.csv(github_csv_url)
head(data)