library(readr)
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
library(psych)
# Example with full path
data <- read_delim("C:\\Users\\abhir\\OneDrive\\Documents\\luddy\\H510-Stats,R\\adult.csv", delim = ",")
## Rows: 32561 Columns: 15
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (9): Work-Class, Education, Marital Status, Occupation, Relationship, Ra...
## dbl (6): Age, Fnl_Wgt, Education_Level, Capital_Gain, Capital_Loss, hrs_week
## 
## ℹ 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.

Use spec() with your data object

spec(data)

summary(data)



```r
#  dimensions of your data
dim(data)
## [1] 32561    15
# data types of your columns
sapply(data, class)
##             Age      Work-Class         Fnl_Wgt       Education Education_Level 
##       "numeric"     "character"       "numeric"     "character"       "numeric" 
##  Marital Status      Occupation    Relationship            Race             Sex 
##     "character"     "character"     "character"     "character"     "character" 
##    Capital_Gain    Capital_Loss        hrs_week         Country      Annual_pay 
##       "numeric"       "numeric"       "numeric"     "character"     "character"
head(data)
## # A tibble: 6 × 15
##     Age `Work-Class`        Fnl_Wgt Education   Education_Level `Marital Status`
##   <dbl> <chr>                 <dbl> <chr>                 <dbl> <chr>           
## 1    39 " State-gov"          77516 " Bachelor…              13 " Never-married"
## 2    50 " Self-emp-not-inc"   83311 " Bachelor…              13 " Married-civ-s…
## 3    38 " Private"           215646 " HS-grad"                9 " Divorced"     
## 4    53 " Private"           234721 " 11th"                   7 " Married-civ-s…
## 5    28 " Private"           338409 " Bachelor…              13 " Married-civ-s…
## 6    37 " Private"           284582 " Masters"               14 " Married-civ-s…
## # ℹ 9 more variables: Occupation <chr>, Relationship <chr>, Race <chr>,
## #   Sex <chr>, Capital_Gain <dbl>, Capital_Loss <dbl>, hrs_week <dbl>,
## #   Country <chr>, Annual_pay <chr>
table(data$Education)
## 
##          10th          11th          12th       1st-4th       5th-6th 
##           933          1175           433           168           333 
##       7th-8th           9th    Assoc-acdm     Assoc-voc     Bachelors 
##           646           514          1067          1382          5355 
##     Doctorate       HS-grad       Masters     Preschool   Prof-school 
##           413         10501          1723            51           576 
##  Some-college 
##          7291
table(data$Occupation)
## 
##                  ?       Adm-clerical       Armed-Forces       Craft-repair 
##               1843               3770                  9               4099 
##    Exec-managerial    Farming-fishing  Handlers-cleaners  Machine-op-inspct 
##               4066                994               1370               2002 
##      Other-service    Priv-house-serv     Prof-specialty    Protective-serv 
##               3295                149               4140                649 
##              Sales       Tech-support   Transport-moving 
##               3650                928               1597
# Get summary statistics using describe() function
describe(data)
##                 vars     n      mean        sd median   trimmed      mad   min
## Age                1 32561     38.58     13.64     37     37.69    14.83    17
## Work-Class*        2 32561      4.87      1.46      5      4.96     0.00     1
## Fnl_Wgt            3 32561 189778.37 105549.98 178356 180802.36 88798.84 12285
## Education*         4 32561     11.30      3.87     12     11.81     2.97     1
## Education_Level    5 32561     10.08      2.57     10     10.19     1.48     1
## Marital Status*    6 32561      3.61      1.51      3      3.65     2.97     1
## Occupation*        7 32561      7.57      4.23      8      7.50     5.93     1
## Relationship*      8 32561      2.45      1.61      2      2.25     1.48     1
## Race*              9 32561      4.67      0.85      5      4.90     0.00     1
## Sex*              10 32561      1.67      0.47      2      1.71     0.00     1
## Capital_Gain      11 32561   1077.65   7385.29      0      0.00     0.00     0
## Capital_Loss      12 32561     87.30    402.96      0      0.00     0.00     0
## hrs_week          13 32561     40.44     12.35     40     40.55     4.45     1
## Country*          14 32561     37.72      7.82     40     40.00     0.00     1
## Annual_pay*       15 32561      1.24      0.43      1      1.18     0.00     1
##                     max   range  skew kurtosis     se
## Age                  90      73  0.56    -0.17   0.08
## Work-Class*           9       8 -0.75     1.68   0.01
## Fnl_Wgt         1484705 1472420  1.45     6.22 584.94
## Education*           16      15 -0.93     0.68   0.02
## Education_Level      16      15 -0.31     0.62   0.01
## Marital Status*       7       6 -0.01    -0.54   0.01
## Occupation*          15      14  0.11    -1.23   0.02
## Relationship*         6       5  0.79    -0.77   0.01
## Race*                 5       4 -2.44     4.87   0.00
## Sex*                  2       1 -0.72    -1.48   0.00
## Capital_Gain      99999   99999 11.95   154.77  40.93
## Capital_Loss       4356    4356  4.59    20.37   2.23
## hrs_week             99      98  0.23     2.92   0.07
## Country*             42      41 -3.66    12.53   0.04
## Annual_pay*           2       1  1.21    -0.53   0.00
colnames(data)
##  [1] "Age"             "Work-Class"      "Fnl_Wgt"         "Education"      
##  [5] "Education_Level" "Marital Status"  "Occupation"      "Relationship"   
##  [9] "Race"            "Sex"             "Capital_Gain"    "Capital_Loss"   
## [13] "hrs_week"        "Country"         "Annual_pay"
str(data)
## spc_tbl_ [32,561 × 15] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ Age            : num [1:32561] 39 50 38 53 28 37 49 52 31 42 ...
##  $ Work-Class     : chr [1:32561] " State-gov" " Self-emp-not-inc" " Private" " Private" ...
##  $ Fnl_Wgt        : num [1:32561] 77516 83311 215646 234721 338409 ...
##  $ Education      : chr [1:32561] " Bachelors" " Bachelors" " HS-grad" " 11th" ...
##  $ Education_Level: num [1:32561] 13 13 9 7 13 14 5 9 14 13 ...
##  $ Marital Status : chr [1:32561] " Never-married" " Married-civ-spouse" " Divorced" " Married-civ-spouse" ...
##  $ Occupation     : chr [1:32561] " Adm-clerical" " Exec-managerial" " Handlers-cleaners" " Handlers-cleaners" ...
##  $ Relationship   : chr [1:32561] " Not-in-family" " Husband" " Not-in-family" " Husband" ...
##  $ Race           : chr [1:32561] " White" " White" " White" " Black" ...
##  $ Sex            : chr [1:32561] " Male" " Male" " Male" " Male" ...
##  $ Capital_Gain   : num [1:32561] 2174 0 0 0 0 ...
##  $ Capital_Loss   : num [1:32561] 0 0 0 0 0 0 0 0 0 0 ...
##  $ hrs_week       : num [1:32561] 40 13 40 40 40 40 16 45 50 40 ...
##  $ Country        : chr [1:32561] " United-States" " United-States" " United-States" " United-States" ...
##  $ Annual_pay     : chr [1:32561] " <=50K" " <=50K" " <=50K" " <=50K" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   Age = col_double(),
##   ..   `Work-Class` = col_character(),
##   ..   Fnl_Wgt = col_double(),
##   ..   Education = col_character(),
##   ..   Education_Level = col_double(),
##   ..   `Marital Status` = col_character(),
##   ..   Occupation = col_character(),
##   ..   Relationship = col_character(),
##   ..   Race = col_character(),
##   ..   Sex = col_character(),
##   ..   Capital_Gain = col_double(),
##   ..   Capital_Loss = col_double(),
##   ..   hrs_week = col_double(),
##   ..   Country = col_character(),
##   ..   Annual_pay = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>
# Assuming 'data' is your data frame
# Example for a numeric column 'Age'
data$Age <- as.numeric(data$Age)
hist(data$Age, main = "Histogram of Age", xlab = "Age", col = "lightblue")



```r
# Install and load the ggplot2 package if not already installed
install.packages("ggplot2")
## Installing package into 'C:/Users/abhir/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'ggplot2' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\abhir\AppData\Local\Temp\RtmpwVSoIN\downloaded_packages
library(ggplot2)
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
## 
##     %+%, alpha
ggplot(data, aes(x = Age)) +
  geom_histogram(fill = "lightblue", color = "black", bins = 30) +
  labs(title = "Histogram of Age", x = "Age")

# plot with  'Age' and 'Education_Level'
plot(data$Age, data$hrs_week, type = "l", col = "blue", xlab = "Age", ylab = "hrs_week")

ggplot(data, aes(x = Age)) +
  geom_histogram(fill = "lightblue", color = "black", bins = 30) +
  labs(title = "Histogram of Age", x = "Age")