1. Use the summary function to gain an overview of the data set. Then display the mean and median for at least two attributes

df<- read.csv(file="https://raw.githubusercontent.com/nnaemeka-git/payment/268bd51d03488e5c388231fa038fe0f86635433b/CreditCard.csv")
head(df)
##   X card reports      age income       share expenditure owner selfemp
## 1 1  yes       0 37.66667 4.5200 0.033269910  124.983300   yes      no
## 2 2  yes       0 33.25000 2.4200 0.005216942    9.854167    no      no
## 3 3  yes       0 33.66667 4.5000 0.004155556   15.000000   yes      no
## 4 4  yes       0 30.50000 2.5400 0.065213780  137.869200    no      no
## 5 5  yes       0 32.16667 9.7867 0.067050590  546.503300   yes      no
## 6 6  yes       0 23.25000 2.5000 0.044438400   91.996670    no      no
##   dependents months majorcards active
## 1          3     54          1     12
## 2          3     34          1     13
## 3          4     58          1      5
## 4          0     25          1      7
## 5          2     64          1      5
## 6          0     54          1      1
summary(df)
##        X              card              reports             age         
##  Min.   :   1.0   Length:1319        Min.   : 0.0000   Min.   : 0.1667  
##  1st Qu.: 330.5   Class :character   1st Qu.: 0.0000   1st Qu.:25.4167  
##  Median : 660.0   Mode  :character   Median : 0.0000   Median :31.2500  
##  Mean   : 660.0                      Mean   : 0.4564   Mean   :33.2131  
##  3rd Qu.: 989.5                      3rd Qu.: 0.0000   3rd Qu.:39.4167  
##  Max.   :1319.0                      Max.   :14.0000   Max.   :83.5000  
##      income           share            expenditure          owner          
##  Min.   : 0.210   Min.   :0.0001091   Min.   :   0.000   Length:1319       
##  1st Qu.: 2.244   1st Qu.:0.0023159   1st Qu.:   4.583   Class :character  
##  Median : 2.900   Median :0.0388272   Median : 101.298   Mode  :character  
##  Mean   : 3.365   Mean   :0.0687322   Mean   : 185.057                     
##  3rd Qu.: 4.000   3rd Qu.:0.0936168   3rd Qu.: 249.036                     
##  Max.   :13.500   Max.   :0.9063205   Max.   :3099.505                     
##    selfemp            dependents         months         majorcards    
##  Length:1319        Min.   :0.0000   Min.   :  0.00   Min.   :0.0000  
##  Class :character   1st Qu.:0.0000   1st Qu.: 12.00   1st Qu.:1.0000  
##  Mode  :character   Median :1.0000   Median : 30.00   Median :1.0000  
##                     Mean   :0.9939   Mean   : 55.27   Mean   :0.8173  
##                     3rd Qu.:2.0000   3rd Qu.: 72.00   3rd Qu.:1.0000  
##                     Max.   :6.0000   Max.   :540.00   Max.   :1.0000  
##      active      
##  Min.   : 0.000  
##  1st Qu.: 2.000  
##  Median : 6.000  
##  Mean   : 6.997  
##  3rd Qu.:11.000  
##  Max.   :46.000
#Mean Age and Income
mean(df$age,na.rm=TRUE)
## [1] 33.2131
mean(df$income,na.rm=TRUE)
## [1] 3.365376
mean(df$expenditure,na.rm=TRUE)
## [1] 185.0571
#Median Age and Income
median(df$age,na.rm=TRUE)
## [1] 31.25
median(df$income,na.rm=TRUE)
## [1] 2.9
median(df$expenditure,na.rm=TRUE)
## [1] 101.2983

2. Create a new data frame with a subset of the columns and rows. Make sure to rename it

NewDf<-df[0:1000,c('age','income','expenditure')]
head(NewDf,n=10)
##         age income expenditure
## 1  37.66667 4.5200  124.983300
## 2  33.25000 2.4200    9.854167
## 3  33.66667 4.5000   15.000000
## 4  30.50000 2.5400  137.869200
## 5  32.16667 9.7867  546.503300
## 6  23.25000 2.5000   91.996670
## 7  27.91667 3.9600   40.833330
## 8  29.16667 2.3700  150.790000
## 9  37.00000 3.8000  777.821700
## 10 28.41667 3.2000   52.580000

3. Create new column names for the new data frame.

NewCol <- c('NewAge','NewIncome','NewExpenditure')
colnames(NewDf)<-NewCol
head(NewDf,n=10)
##      NewAge NewIncome NewExpenditure
## 1  37.66667    4.5200     124.983300
## 2  33.25000    2.4200       9.854167
## 3  33.66667    4.5000      15.000000
## 4  30.50000    2.5400     137.869200
## 5  32.16667    9.7867     546.503300
## 6  23.25000    2.5000      91.996670
## 7  27.91667    3.9600      40.833330
## 8  29.16667    2.3700     150.790000
## 9  37.00000    3.8000     777.821700
## 10 28.41667    3.2000      52.580000

4. Use the summary function to create an overview of your new data frame. The print the mean

and median for the same two attributes. Please compare.

summary(NewDf)
##      NewAge          NewIncome      NewExpenditure    
##  Min.   : 0.1667   Min.   : 1.200   Min.   :   0.000  
##  1st Qu.:25.2500   1st Qu.: 2.250   1st Qu.:   6.479  
##  Median :30.7083   Median : 2.956   Median : 100.809  
##  Mean   :32.8448   Mean   : 3.392   Mean   : 183.060  
##  3rd Qu.:38.9375   3rd Qu.: 4.000   3rd Qu.: 250.771  
##  Max.   :83.5000   Max.   :13.500   Max.   :3099.505
#Mean NewAge, NewIncome and NewExpenditure
mean(NewDf$NewAge,na.rm=TRUE)
## [1] 32.84483
mean(NewDf$NewIncome,na.rm=TRUE)
## [1] 3.392053
mean(NewDf$NewExpenditure,na.rm=TRUE)
## [1] 183.0595
#Median NewAge, NewIncome and NewExpenditure
median(NewDf$NewAge,na.rm=TRUE)
## [1] 30.70833
median(NewDf$NewIncome,na.rm=TRUE)
## [1] 2.95615
median(NewDf$NewExpenditure,na.rm=TRUE)
## [1] 100.8088
# The mean and midian values of age, income and expenditure changed slitly as a result of the dataset being subsetted 

5. For at least 3 values in a column please rename so that every value in that column is renamed.

df$owner[df$owner %in% c('no','yes')]<-c('third party','custodian')
## Warning in df$owner[df$owner %in% c("no", "yes")] <- c("third party",
## "custodian"): number of items to replace is not a multiple of replacement length
head(df)
##   X card reports      age income       share expenditure       owner selfemp
## 1 1  yes       0 37.66667 4.5200 0.033269910  124.983300 third party      no
## 2 2  yes       0 33.25000 2.4200 0.005216942    9.854167   custodian      no
## 3 3  yes       0 33.66667 4.5000 0.004155556   15.000000 third party      no
## 4 4  yes       0 30.50000 2.5400 0.065213780  137.869200   custodian      no
## 5 5  yes       0 32.16667 9.7867 0.067050590  546.503300 third party      no
## 6 6  yes       0 23.25000 2.5000 0.044438400   91.996670   custodian      no
##   dependents months majorcards active
## 1          3     54          1     12
## 2          3     34          1     13
## 3          4     58          1      5
## 4          0     25          1      7
## 5          2     64          1      5
## 6          0     54          1      1

6. Display enough rows to see examples of all of steps 1-5 above.

head(df,n=50)
##     X card reports      age income       share expenditure       owner selfemp
## 1   1  yes       0 37.66667 4.5200 0.033269910  124.983300 third party      no
## 2   2  yes       0 33.25000 2.4200 0.005216942    9.854167   custodian      no
## 3   3  yes       0 33.66667 4.5000 0.004155556   15.000000 third party      no
## 4   4  yes       0 30.50000 2.5400 0.065213780  137.869200   custodian      no
## 5   5  yes       0 32.16667 9.7867 0.067050590  546.503300 third party      no
## 6   6  yes       0 23.25000 2.5000 0.044438400   91.996670   custodian      no
## 7   7  yes       0 27.91667 3.9600 0.012575760   40.833330 third party      no
## 8   8  yes       0 29.16667 2.3700 0.076433760  150.790000   custodian      no
## 9   9  yes       0 37.00000 3.8000 0.245627900  777.821700 third party      no
## 10 10  yes       0 28.41667 3.2000 0.019780000   52.580000   custodian      no
## 11 11  yes       0 30.50000 3.9500 0.078024560  256.664200 third party      no
## 12 12   no       0 42.00000 1.9800 0.000606061    0.000000   custodian      no
## 13 13   no       0 30.00000 1.7300 0.000693642    0.000000 third party      no
## 14 14  yes       0 28.83333 2.4500 0.038795510   78.874170   custodian      no
## 15 15  yes       0 35.33333 1.9080 0.026906710   42.615000 third party      no
## 16 16  yes       0 41.16667 3.2000 0.125819400  335.435000   custodian      no
## 17 17  yes       0 40.08333 4.0000 0.074815750  248.719200 third party      no
## 18 18   no       7 29.50000 3.0000 0.000400000    0.000000   custodian      no
## 19 19  yes       0 39.50000 9.9999 0.065794860  548.035000 third party     yes
## 20 20   no       3 45.75000 3.4000 0.000352941    0.000000   custodian      no
## 21 21  yes       0 35.25000 2.3500 0.022385960   43.339170 third party      no
## 22 22   no       1 25.16667 1.8750 0.000640000    0.000000   custodian      no
## 23 23  yes       0 34.25000 2.0000 0.131112000  218.520000 third party      no
## 24 24  yes       1 35.75000 4.0000 0.051192250  170.640800   custodian      no
## 25 25  yes       0 42.66667 5.1400 0.008949417   37.583330 third party      no
## 26 26  yes       0 30.25000 4.5060 0.133742100  502.201700   custodian      no
## 27 27   no       0 21.66667 3.8400 0.000312500    0.000000 third party     yes
## 28 28  yes       0 22.25000 1.5000 0.058608000   73.176670   custodian      no
## 29 29   no       0 34.25000 2.5000 0.000480000    0.000000 third party      no
## 30 30  yes       0 40.00000 5.5000 0.334459600 1532.773000   custodian      no
## 31 31  yes       0 21.83333 2.0272 0.025320140   42.690830 third party      no
## 32 32  yes       1 29.41667 3.2000 0.156719400  417.835000   custodian      no
## 33 33   no       1 24.91667 3.1500 0.000380952    0.000000 third party      no
## 34 34  yes       0 21.00000 2.4663 0.268932800  552.724200   custodian      no
## 35 35  yes       0 23.83333 3.0000 0.089015660  222.539200 third party      no
## 36 36  yes       0 42.83333 3.5412 0.183456200  541.295800   custodian      no
## 37 37   no       0 42.58333 2.2845 0.000525279    0.000000 third party      no
## 38 38  yes       0 36.58333 5.7000 0.119741900  568.774200   custodian      no
## 39 39  yes       0 26.75000 3.5000 0.118104300  344.470800 third party      no
## 40 40  yes       0 27.75000 4.6000 0.105743900  405.351700   custodian      no
## 41 41  yes       0 26.25000 3.0000 0.124375000  310.937500 third party      no
## 42 42  yes       0 23.33333 2.5850 0.025057640   53.645000   custodian      no
## 43 43  yes       0 29.91667 1.5100 0.051258280   63.916670 third party      no
## 44 44  yes       0 30.00000 1.8500 0.107581600  165.855000   custodian      no
## 45 45  yes       0 38.33333 2.6000 0.004807692    9.583333 third party      no
## 46 46   no       0 28.16667 1.8000 0.000666667    0.000000   custodian     yes
## 47 47  yes       0 35.58333 2.0000 0.192044000  319.490000 third party      no
## 48 48   no       0 37.75000 3.2628 0.000367782    0.000000   custodian      no
## 49 49  yes       0 26.08333 2.3500 0.042851060   83.083340 third party      no
## 50 50  yes       0 27.75000 7.0000 0.110584900  644.828300   custodian      no
##    dependents months majorcards active
## 1           3     54          1     12
## 2           3     34          1     13
## 3           4     58          1      5
## 4           0     25          1      7
## 5           2     64          1      5
## 6           0     54          1      1
## 7           2      7          1      5
## 8           0     77          1      3
## 9           0     97          1      6
## 10          0     65          1     18
## 11          1     24          1     20
## 12          2     36          1      0
## 13          1     42          0     12
## 14          0     26          1      3
## 15          2    120          0      5
## 16          1    168          1     22
## 17          2     96          1      0
## 18          2     60          1      8
## 19          0     28          1      0
## 20          0     28          1     10
## 21          2    115          1      1
## 22          2      7          0      2
## 23          0     12          1      0
## 24          2     18          1     22
## 25          2     13          1     17
## 26          2     38          1      7
## 27          1     12          0      1
## 28          0     64          1      6
## 29          1     12          1      0
## 30          4     74          1     19
## 31          0      9          0      5
## 32          0     14          1      6
## 33          1     40          1      5
## 34          1     12          1     10
## 35          0     12          1      5
## 36          6    108          1     15
## 37          2     46          1      0
## 38          1     36          1     16
## 39          0      2          1     14
## 40          4     28          1     13
## 41          0      7          1     10
## 42          0      8          1      1
## 43          1      7          0      1
## 44          0     60          1     12
## 45          0     12          1      1
## 46          2     26          1      2
## 47          0    156          1      4
## 48          1     98          0      1
## 49          1     30          0      2
## 50          0      0          1     13