Load Libraries

library(tidyverse) # for the map() command
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── 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(psych) # for the describe() command
## 
## Attaching package: 'psych'
## 
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
library(naniar) # for the gg_miss_upset() command
library(expss) # for the cross_cases() command
## Loading required package: maditr
## 
## Use magrittr pipe '%>%' to chain several operations:
##              mtcars %>%
##                  let(mpg_hp = mpg/hp) %>%
##                  take(mean(mpg_hp), by = am)
##         
## 
## 
## Attaching package: 'maditr'
## 
## The following objects are masked from 'package:dplyr':
## 
##     between, coalesce, first, last
## 
## The following object is masked from 'package:purrr':
## 
##     transpose
## 
## The following object is masked from 'package:readr':
## 
##     cols
## 
## 
## Attaching package: 'expss'
## 
## The following object is masked from 'package:naniar':
## 
##     is_na
## 
## The following objects are masked from 'package:stringr':
## 
##     fixed, regex
## 
## The following objects are masked from 'package:dplyr':
## 
##     compute, contains, na_if, recode, vars, where
## 
## The following objects are masked from 'package:purrr':
## 
##     keep, modify, modify_if, when
## 
## The following objects are masked from 'package:tidyr':
## 
##     contains, nest
## 
## The following object is masked from 'package:ggplot2':
## 
##     vars

Import Data

# use the read.csv() command to import your downloaded csv file
df <- read.csv("EAMMi2-Data1.2.csv", header=T)

Viewing Data

# use the names() command to view the list of columns or variables in your dataframe
names(df)
##   [1] "StartDate"             "EndDate"               "Status"               
##   [4] "Progress"              "Duration..in.seconds." "Finished"             
##   [7] "RecordedDate"          "ResponseId"            "RecipientLastName"    
##  [10] "RecipientFirstName"    "RecipientEmail"        "ExternalReference"    
##  [13] "DistributionChannel"   "informedconsent"       "moa1.1_1"             
##  [16] "moa1.1_2"              "moa1.1_3"              "moa1.1_4"             
##  [19] "moa1.1_5"              "moa1.1_6"              "moa1.1_7"             
##  [22] "moa1.1_8"              "moa1.1_9"              "moa1.1_10"            
##  [25] "moa1.2_1"              "moa1.2_2"              "moa1.2_3"             
##  [28] "moa1.2_4"              "moa1.2_5"              "moa1.2_6"             
##  [31] "moa1.2_7"              "moa1.2_8"              "moa1.2_9"             
##  [34] "moa1.2_10"             "moa2.1_1"              "moa2.1_2"             
##  [37] "moa2.1_3"              "moa2.1_4"              "moa2.1_5"             
##  [40] "moa2.1_6"              "moa2.1_7"              "moa2.1_8"             
##  [43] "moa2.1_9"              "moa2.1_10"             "moa2.2_1"             
##  [46] "moa2.2_2"              "moa2.2_3"              "moa2.2_4"             
##  [49] "moa2.2_5"              "moa2.2_6"              "moa2.2_7"             
##  [52] "moa2.2_8"              "moa2.2_9"              "moa2.2_10"            
##  [55] "adult_Q"               "MOA_IMP_biascheck"     "MOA_ach_biascheck"    
##  [58] "MOA_IMP_dummy"         "MOA.ACH_dummy"         "Q65_First.Click"      
##  [61] "Q65_Last.Click"        "Q65_Page.Submit"       "Q65_Click.Count"      
##  [64] "IDEA_1"                "IDEA_2"                "IDEA_3"               
##  [67] "IDEA_4"                "IDEA_5"                "IDEA_6"               
##  [70] "IDEA_7"                "IDEA_8"                "IDEA.biascheck"       
##  [73] "IDEA.bias.dummy"       "Q66_First.Click"       "Q66_Last.Click"       
##  [76] "Q66_Page.Submit"       "Q66_Click.Count"       "politics"             
##  [79] "party"                 "president"             "Q74_First.Click"      
##  [82] "Q74_Last.Click"        "Q74_Page.Submit"       "Q74_Click.Count"      
##  [85] "swb_1"                 "swb_2"                 "swb_3"                
##  [88] "swb_4"                 "swb_5"                 "swb_6"                
##  [91] "Q67_First.Click"       "Q67_Last.Click"        "Q67_Page.Submit"      
##  [94] "Q67_Click.Count"       "mindful_1"             "mindful_2"            
##  [97] "mindful_3"             "mindful_4"             "mindful_5"            
## [100] "mindful_6"             "mindful_7"             "mindful_8"            
## [103] "mindful_9"             "mindful_10"            "mindful_11"           
## [106] "mindful_12"            "mindful_13"            "mindful_14"           
## [109] "mindful_15"            "mindful_biascheck"     "mindful_bias_dummy"   
## [112] "Q68_First.Click"       "Q68_Last.Click"        "Q68_Page.Submit"      
## [115] "Q68_Click.Count"       "belong_1"              "belong_2"             
## [118] "belong_3"              "belong_4"              "belong_5"             
## [121] "belong_6"              "belong_7"              "belong_8"             
## [124] "belong_9"              "belong_10"             "belnow"               
## [127] "belong_biascheck"      "belong_bias_dummy"     "Q72_First.Click"      
## [130] "Q72_Last.Click"        "Q72_Page.Submit"       "Q72_Click.Count"      
## [133] "efficacy_1"            "efficacy_2"            "efficacy_3"           
## [136] "efficacy_4"            "efficacy_5"            "efficacy_6"           
## [139] "efficacy_7"            "efficacy_8"            "efficacy_9"           
## [142] "efficacy_10"           "efficacy_biascheck"    "efficacy_bias_dummy"  
## [145] "Q77_First.Click"       "Q77_Last.Click"        "Q77_Page.Submit"      
## [148] "Q77_Click.Count"       "support_1"             "support_2"            
## [151] "support_3"             "support_4"             "support_5"            
## [154] "support_6"             "support_7"             "support_8"            
## [157] "support_9"             "support_10"            "support_11"           
## [160] "support_12"            "support_biascheck"     "support_bias_dummy"   
## [163] "Q96_First.Click"       "Q96_Last.Click"        "Q96_Page.Submit"      
## [166] "Q96_Click.Count"       "SocMedia_1"            "SocMedia_2"           
## [169] "SocMedia_3"            "SocMedia_4"            "SocMedia_5"           
## [172] "SocMedia_6"            "SocMedia_7"            "SocMedia_8"           
## [175] "SocMedia_9"            "SocMedia_10"           "SocMedia_11"          
## [178] "SocMedia_biascheck"    "SocMedia_bias_dummy"   "Q80_First.Click"      
## [181] "Q80_Last.Click"        "Q80_Page.Submit"       "Q80_Click.Count"      
## [184] "usdream_1"             "usdream_2"             "usdream_3"            
## [187] "Q73_First.Click"       "Q73_Last.Click"        "Q73_Page.Submit"      
## [190] "Q73_Click.Count"       "freq"                  "transgres"            
## [193] "relation"              "relation_10_TEXT"      "fault"                
## [196] "feel"                  "common"                "attenion2"            
## [199] "Q78_First.Click"       "Q78_Last.Click"        "Q78_Page.Submit"      
## [202] "Q78_Click.Count"       "transgres_1"           "transgres_2"          
## [205] "transgres_3"           "transgres_4"           "Q79_First.Click"      
## [208] "Q79_Last.Click"        "Q79_Page.Submit"       "Q79_Click.Count"      
## [211] "NPI1"                  "NPI2"                  "NPI3"                 
## [214] "NPI4"                  "NPI5"                  "NPI6"                 
## [217] "NPI7"                  "NPI8"                  "NPI9"                 
## [220] "NPI10"                 "NPI11"                 "NPI12"                
## [223] "NPI13"                 "exploit_1"             "exploit_2"            
## [226] "exploit_3"             "NPI_biascheck"         "NPI_bias_dummy"       
## [229] "Q76_First.Click"       "Q76_Last.Click"        "Q76_Page.Submit"      
## [232] "Q76_Click.Count"       "Q11"                   "Q14_1"                
## [235] "Q14_2"                 "Q14_3"                 "Q14_4"                
## [238] "Q14_5"                 "Q14_6"                 "Q14_6_TEXT"           
## [241] "Q10_1"                 "Q10_2"                 "Q10_3"                
## [244] "Q10_4"                 "Q10_5"                 "Q10_6"                
## [247] "Q10_7"                 "Q10_8"                 "Q10_9"                
## [250] "Q10_10"                "Q10_11"                "Q10_12"               
## [253] "Q10_13"                "Q10_14"                "Q10_15"               
## [256] "Q71_First.Click"       "Q71_Last.Click"        "Q71_Page.Submit"      
## [259] "Q71_Click.Count"       "physSx_1"              "physSx_2"             
## [262] "physSx_3"              "physSx_4"              "physSx_5"             
## [265] "physSx_6"              "physSx_7"              "physSx_8"             
## [268] "physSx_9"              "physSx_10"             "physSx_11"            
## [271] "physSx_12"             "physSx_13"             "phys_sx_biaschec"     
## [274] "phys_sym_bias_dummy."  "Q70_First.Click"       "Q70_Last.Click"       
## [277] "Q70_Page.Submit"       "Q70_Click.Count"       "stress_1"             
## [280] "stress_2"              "stress_3"              "stress_4"             
## [283] "stress_5"              "stress_6"              "stress_7"             
## [286] "stress_8"              "stress_9"              "stress_10"            
## [289] "stress_biascheck"      "stress_bias_dummy"     "Q69_First.Click"      
## [292] "Q69_Last.Click"        "Q69_Page.Submit"       "Q69_Click.Count"      
## [295] "marriage1_1"           "marriage1_2"           "marriage1_3"          
## [298] "marriage1_4"           "marriage2"             "marriage3"            
## [301] "marriage4"             "marriage5"             "Q75_First.Click"      
## [304] "Q75_Last.Click"        "Q75_Page.Submit"       "Q75_Click.Count"      
## [307] "school"                "sex"                   "age"                  
## [310] "edu"                   "sibling"               "race"                 
## [313] "race_6_TEXT"           "Q82"                   "Q83"                  
## [316] "income"                "place2"                "Q80"                  
## [319] "place"                 "Q81"                   "Q81_First.Click"      
## [322] "Q81_Last.Click"        "Q81_Page.Submit"       "Q81_Click.Count"      
## [325] "comments"              "affiliation"           "response_bias_SUM"    
## [328] "school_coded"
# use the head command to view the first few lines of your dataframe
head(df)
##   StartDate  EndDate Status Progress Duration..in.seconds. Finished
## 1  12/02/16 12/02/16      0      100                  1839        1
## 2  11/16/16 11/16/16      0      100                  1467        1
## 3  11/09/16 11/09/16      0       99                  2185        0
## 4  11/07/16 11/07/16      0      100                  2904        1
## 5  11/18/16 11/18/16      0      100                  1229        1
## 6  11/07/16 11/07/16      0      100                  2068        1
##       RecordedDate        ResponseId RecipientLastName RecipientFirstName
## 1   12/2/2016 5:38 R_BJN3bQqi1zUMid3                NA                 NA
## 2 11/16/2016 11:53 R_2TGbiBXmAtxywsD                NA                 NA
## 3  11/16/2016 1:22 R_12G7bIqN2wB2N65                NA                 NA
## 4   11/7/2016 4:54 R_39pldNoon8CePfP                NA                 NA
## 5  11/18/2016 0:30 R_1QiKb2LdJo1Bhvv                NA                 NA
## 6  11/7/2016 14:42 R_pmwDTZyCyCycXwB                NA                 NA
##   RecipientEmail ExternalReference DistributionChannel informedconsent moa1.1_1
## 1             NA                NA           anonymous               1        4
## 2             NA                NA           anonymous               1        4
## 3             NA                NA           anonymous               1        4
## 4             NA                NA           anonymous               1        4
## 5             NA                NA           anonymous               1        4
## 6             NA                NA           anonymous               1        4
##   moa1.1_2 moa1.1_3 moa1.1_4 moa1.1_5 moa1.1_6 moa1.1_7 moa1.1_8 moa1.1_9
## 1        4        3        2        2        3        2        1        4
## 2        4        4        2        3        3        4        3        3
## 3        4        4        1        1        4        2        3        4
## 4        3        3        1        1        2        1        1        1
## 5        4        4        1        1        3        1        1        4
## 6        3        4        2        3        4        2        1        3
##   moa1.1_10 moa1.2_1 moa1.2_2 moa1.2_3 moa1.2_4 moa1.2_5 moa1.2_6 moa1.2_7
## 1         3        2        1        2        1        1        1        2
## 2         3        1        1        2        2        1        1        1
## 3         3        2        1        1        1        1        1        2
## 4         1        1        1        1        1        1        1        2
## 5         3        2        1        2        1        3        3        1
## 6         4        1        1        1        1        1        1        1
##   moa1.2_8 moa1.2_9 moa1.2_10 moa2.1_1 moa2.1_2 moa2.1_3 moa2.1_4 moa2.1_5
## 1        3        3         2        4        4        4        4        3
## 2        1        2         3        3        4        2        4        4
## 3        3        3         3        4        2        2        4        3
## 4        3        2         3        4        2        2        4        3
## 5        1        3         2        4        4        3        4        4
## 6        1        1         3        4        4        4        4        2
##   moa2.1_6 moa2.1_7 moa2.1_8 moa2.1_9 moa2.1_10 moa2.2_1 moa2.2_2 moa2.2_3
## 1        4        4        4        3         2        2        1        1
## 2        3        2        4        2         1        3        1        2
## 3        3        4        4        3         2        2        1        1
## 4        2        4        2        3         2        2        1        1
## 5        3        4        4        3         3        3        3        3
## 6        4        3        4        4         4        2        1        1
##   moa2.2_4 moa2.2_5 moa2.2_6 moa2.2_7 moa2.2_8 moa2.2_9 moa2.2_10 adult_Q
## 1        3        2        3        3        2        2         1       1
## 2        2        1        2        2        2        2         1       1
## 3        2        1        2        3        1        1         1       1
## 4        2        1        2        2        2        2         1       1
## 5        3        3        2        3        3        2         3       1
## 6        2        1        2        2        1        2         1       1
##   MOA_IMP_biascheck MOA_ach_biascheck MOA_IMP_dummy MOA.ACH_dummy
## 1                64                38             0             0
## 2                62                33             0             0
## 3                61                33             0             0
## 4                46                32             0             0
## 5                62                47             0             0
## 6                67                27             0             0
##   Q65_First.Click Q65_Last.Click Q65_Page.Submit Q65_Click.Count IDEA_1 IDEA_2
## 1          37.139        307.731         308.890              45      3      4
## 2         120.026        336.428         338.177              58      4      4
## 3          27.705        154.447         155.544              47      4      4
## 4          19.656        297.285         298.509              43      4      4
## 5          12.867        121.932         122.254              46      4      4
## 6          15.652        223.372         225.431              50      3      4
##   IDEA_3 IDEA_4 IDEA_5 IDEA_6 IDEA_7 IDEA_8 IDEA.biascheck IDEA.bias.dummy
## 1      4      3      4      4      4      4             30               0
## 2      4      4      3      4      4      4             31               0
## 3      4      4      4      4      3      3             30               0
## 4      3      3      4      4      4      4             30               0
## 5      3      4      3      3      3      4             28               0
## 6      3      3      4      4      3      2             26               0
##   Q66_First.Click Q66_Last.Click Q66_Page.Submit Q66_Click.Count politics party
## 1          44.705         86.585          87.514              11        2     3
## 2          19.927         65.200          67.162              13        1     4
## 3          23.170         51.401          52.408              11        2     8
## 4          27.467        172.797         174.119               9        8     8
## 5          23.952         52.176          53.355               9        1     8
## 6           9.475         72.935          73.937              13        8     8
##                                                                            president
## 1                                                                                   
## 2 None, but I was a US Citizen and had a gun next to my head, I would vote for Trump
## 3                                                                    Hillary Clinton
## 4                                                                    Hillary Clinton
## 5                                                                            Sanders
## 6                                                                            No one.
##   Q74_First.Click Q74_Last.Click Q74_Page.Submit Q74_Click.Count swb_1 swb_2
## 1          13.052         40.445          46.399               2     4     6
## 2           4.899         28.125          55.107               6     3     4
## 3          34.868         48.402          56.371               4     1     2
## 4          66.886        119.219         135.295               4     5     6
## 5          23.614         32.221          35.338               4     2     5
## 6          12.314         41.232          54.436               6     4     4
##   swb_3 swb_4 swb_5 swb_6 Q67_First.Click Q67_Last.Click Q67_Page.Submit
## 1     5     5     3     3           9.627         40.388          41.198
## 2     5     5     4     4           8.607         29.115          29.955
## 3     2     2     2     2          37.656         53.240          54.603
## 4     6     5     6     3          13.587         55.197          56.150
## 5     5     3     2     5           6.798         22.246          23.138
## 6     6     5     1     4           7.927         44.108          48.227
##   Q67_Click.Count mindful_1 mindful_2 mindful_3 mindful_4 mindful_5 mindful_6
## 1               7         4         2         2         2         4         1
## 2               7         2         2         2         1         3         1
## 3               9         2         3         1         2         3         1
## 4               7         2         2         1         2         2         1
## 5               7         4         5         3         2         4         1
## 6               7         1         4         3         3         5         1
##   mindful_7 mindful_8 mindful_9 mindful_10 mindful_11 mindful_12 mindful_13
## 1         2         2         2          2          2          4          1
## 2         1         1         2          2          1          2          1
## 3         2         2         5          3          2          1          1
## 4         2         2         3          2          2          3          3
## 5         4         2         1          2          2          6          5
## 6         5         6         3          5          1          3          2
##   mindful_14 mindful_15 mindful_biascheck mindful_bias_dummy Q68_First.Click
## 1          2          4                36                  0          32.692
## 2          1          5                27                  0          13.184
## 3          1          4                33                  0          48.022
## 4          2          4                33                  0         110.432
## 5          2          5                48                  0          81.124
## 6          4          5                51                  0          33.458
##   Q68_Last.Click Q68_Page.Submit Q68_Click.Count belong_1 belong_2 belong_3
## 1        154.123         157.391              15        4        2        4
## 2         76.856          77.629              22        2        3        1
## 3        142.665         143.398              20        4        4        2
## 4        255.734         257.134              17        3        4        1
## 5        134.499         135.848              16        4        3        3
## 6        212.770         213.511              25        2        3        2
##   belong_4 belong_5 belong_6 belong_7 belong_8 belong_9 belong_10 belnow
## 1        4        4        2        5        2        4         3      4
## 2        5        4        4        2        4        5         4      4
## 3        5        4        4        2        3        4         4      2
## 4        5        4        5        2        4        4         4      4
## 5        4        4        5        1        3        2         3      4
## 6        5        4        5        1        4        4         4      3
##   belong_biascheck belong_bias_dummy Q72_First.Click Q72_Last.Click
## 1               38                 0           8.221         80.460
## 2               38                 0           6.774         65.987
## 3               38                 0           5.697         71.192
## 4               40                 0           6.096         86.373
## 5               36                 0          58.613        121.436
## 6               37                 0           6.124         70.638
##   Q72_Page.Submit Q72_Click.Count efficacy_1 efficacy_2 efficacy_3 efficacy_4
## 1          82.781              13          4          3          4          3
## 2          67.158              18          3          3          3          4
## 3          72.176              13          3          3          1          2
## 4          87.231              14          4          1          2          3
## 5         122.620              11          3          3          2          3
## 6          72.503              15          3          2          3          2
##   efficacy_5 efficacy_6 efficacy_7 efficacy_8 efficacy_9 efficacy_10
## 1          3          4          3          3          4           3
## 2          4          4          3          3          3           4
## 3          2          3          1          3          2           2
## 4          2          4          2          3          4           3
## 5          3          3          3          3          4           3
## 6          1          3          2          3          3           2
##   efficacy_biascheck efficacy_bias_dummy Q77_First.Click Q77_Last.Click
## 1                 34                   0          15.372        104.315
## 2                 34                   0          11.711         74.768
## 3                 22                   0          38.964        179.667
## 4                 28                   0          16.050        168.886
## 5                 30                   0          32.150         59.030
## 6                 24                   0           6.259         69.817
##   Q77_Page.Submit Q77_Click.Count support_1 support_2 support_3 support_4
## 1         105.195              11         7         4         6         5
## 2          75.558              21         7         7         7         6
## 3         182.727              13         6         6         5         2
## 4         170.530              10         6         6         7         3
## 5          60.273              11         6         6         5         5
## 6          70.970              13         7         7         6         6
##   support_5 support_6 support_7 support_8 support_9 support_10 support_11
## 1         6         6         7         7         7          4          6
## 2         7         6         6         7         7          7          7
## 3         7         5         5         3         6          6          5
## 4         7         6         5         4         6          6          6
## 5         6         6         7         6         6          6          7
## 6         7         2         2         1         1          7          6
##   support_12 support_biascheck support_bias_dummy Q96_First.Click
## 1          7                72                  0          12.241
## 2          7                81                  0           7.482
## 3          6                62                  0          18.845
## 4          5                67                  0          30.307
## 5          6                72                  0          13.096
## 6          2                54                  0          24.841
##   Q96_Last.Click Q96_Page.Submit Q96_Click.Count SocMedia_1 SocMedia_2
## 1         91.497          92.381              17          4          2
## 2         34.247          35.467              19          3          2
## 3         74.388          76.037              14          3          3
## 4        150.285         151.869              18          4          2
## 5         43.727          45.041              12          3          3
## 6        110.942         111.636              18          1          1
##   SocMedia_3 SocMedia_4 SocMedia_5 SocMedia_6 SocMedia_7 SocMedia_8 SocMedia_9
## 1          5          3          5          5          5          4          5
## 2          4          2          1          1          1          1          2
## 3          4          2          3          4          4          2          3
## 4          5          2          2          4          4          1          3
## 5          5          2          2          4          4          2          4
## 6          2          1          1          1          2          1          1
##   SocMedia_10 SocMedia_11 SocMedia_biascheck SocMedia_bias_dummy
## 1           5           4                 47                   0
## 2           4           2                 23                   0
## 3           3           3                 34                   0
## 4           4           4                 35                   0
## 5           4           4                 37                   0
## 6           1           1                 13                   0
##   Q80_First.Click Q80_Last.Click Q80_Page.Submit Q80_Click.Count usdream_1
## 1          17.470         59.573          60.431              11         4
## 2          10.768         45.340          47.007              15         4
## 3          30.059         66.498          68.018              12         2
## 4         112.432        161.455         163.036              11         1
## 5          22.246         53.406          55.275              12         3
## 6           5.361         89.568          90.785              15         1
##   usdream_2 usdream_3 Q73_First.Click Q73_Last.Click Q73_Page.Submit
## 1         4         1          14.144         24.073          27.558
## 2         4         1           5.240         27.206          36.973
## 3         2         1           5.671         16.751          19.891
## 4         3         1          71.153         82.926          98.687
## 5         4         1          21.293         32.533          35.448
## 6         1         2           6.771         37.203          45.268
##   Q73_Click.Count freq
## 1               3    3
## 2               5    4
## 3               3    6
## 4               3    3
## 5               3    4
## 6               4    2
##                                                                      transgres
## 1 told my friend that something he did was wrong and hurtful to somebody else.
## 2                                                             got very passive
## 3                                                     you don't want to see me
## 4                                I tried to excuse myself and said I was sorry
## 5                                                                  Got angry. 
## 6                                                     why didn't you tell him?
##   relation relation_10_TEXT fault        feel common attenion2 Q78_First.Click
## 1        4                      6           3      3         7          22.366
## 2        7                      2 1,4,5,6,7,8      4         7           6.174
## 3        5                      3           6      5         7           9.705
## 4        4                      3      10,4,6      2         7          58.517
## 5        7                      2         5,6      3        NA           5.647
## 6        6                      3           1      4         7          15.862
##   Q78_Last.Click Q78_Page.Submit Q78_Click.Count transgres_1 transgres_2
## 1        148.934         153.134              12           3           1
## 2         72.626          74.609              22           4           3
## 3        109.167         111.847              10           3           1
## 4        195.290         199.227              14           4           2
## 5         61.894          65.304              13           4           2
## 6        174.894         177.914              21           1           3
##   transgres_3 transgres_4 Q79_First.Click Q79_Last.Click Q79_Page.Submit
## 1           1           1          16.239         27.208          28.488
## 2           2           1          20.400         31.697          32.941
## 3           4           1          57.079         77.311          82.171
## 4           1           1          23.005         49.246          50.303
## 5           2           1          11.727         23.987          25.130
## 6           1           1          14.701         35.077          40.711
##   Q79_Click.Count NPI1 NPI2 NPI3 NPI4 NPI5 NPI6 NPI7 NPI8 NPI9 NPI10 NPI11
## 1               4    1    1    1    2    1    2    2    1    2     2     1
## 2               4    2    2    1    2    1    2    1    1    1     1     2
## 3               5    2    1    1    2    1    2    1    1    1     2     2
## 4               5    2    2    1    2    1    2    2    1    1     2     1
## 5               8    1    2    1    2    1    2    2    2    1     2     1
## 6               6    2    2    2    1    2    2    2    2    1     2     1
##   NPI12 NPI13 exploit_1 exploit_2 exploit_3 NPI_biascheck NPI_bias_dummy
## 1     2     1         2         2         2            19              0
## 2     1     1         4         4         3            18              0
## 3     2     1         5         5         3            19              0
## 4     2     1         2         1         2            20              0
## 5     2     2         5         4         3            21              0
## 6     2     2         1         1         2            23              0
##   Q76_First.Click Q76_Last.Click Q76_Page.Submit Q76_Click.Count Q11 Q14_1
## 1          25.575        141.688         142.668              16   2     2
## 2          10.473        103.989         105.050              35   2     2
## 3          29.957        129.786         132.515              22   2     2
## 4          49.912        222.748         223.703              18   2     2
## 5           5.315        108.076         109.093              25   2     2
## 6           5.353         94.716          98.083              25   2     2
##   Q14_2 Q14_3 Q14_4 Q14_5 Q14_6 Q14_6_TEXT Q10_1 Q10_2 Q10_3 Q10_4 Q10_5 Q10_6
## 1     2     2     2     2     2               NA    NA    NA    NA    NA    NA
## 2     2     2     2     2    NA               NA    NA    NA    NA    NA    NA
## 3     2     2     1     2     2                4     3     4     2     4     5
## 4     2     2     2     2     2               NA    NA    NA    NA    NA    NA
## 5     2     2     2     2    NA               NA    NA    NA    NA    NA    NA
## 6     2     2     2     2     2               NA    NA    NA    NA    NA    NA
##   Q10_7 Q10_8 Q10_9 Q10_10 Q10_11 Q10_12 Q10_13 Q10_14 Q10_15 Q71_First.Click
## 1    NA    NA    NA     NA     NA     NA     NA     NA     NA           5.199
## 2    NA    NA    NA     NA     NA     NA     NA     NA     NA           6.497
## 3     3     1     4      1      3      1      4      2      2           4.533
## 4    NA    NA    NA     NA     NA     NA     NA     NA     NA           7.430
## 5    NA    NA    NA     NA     NA     NA     NA     NA     NA           5.020
## 6    NA    NA    NA     NA     NA     NA     NA     NA     NA          15.872
##   Q71_Last.Click Q71_Page.Submit Q71_Click.Count physSx_1 physSx_2 physSx_3
## 1         28.239          28.669               7        3        1        1
## 2         23.457          24.600               8        2        2        1
## 3        115.299         116.410              21        3        1        1
## 4        122.984         128.490              12        2        3        2
## 5          7.996          17.581               6        1        1        1
## 6         32.719          33.562               7        1        2        2
##   physSx_4 physSx_5 physSx_6 physSx_7 physSx_8 physSx_9 physSx_10 physSx_11
## 1        2        1        2        1        2        2         2         2
## 2        1        3        1        1        3        2         1         1
## 3        3        2        2        1        3        2         1         2
## 4        3        1        2        1        2        1         1         2
## 5        2        1        1        1        1        2         1         1
## 6        1        2        2        1        3        1         2         2
##   physSx_12 physSx_13 phys_sx_biaschec phys_sym_bias_dummy. Q70_First.Click
## 1         3         2               24                    0          13.703
## 2         3         3               24                    0           5.209
## 3         3         3               27                    0          36.694
## 4         3         2               25                    0          47.764
## 5         2         1               16                    0           4.561
## 6         3         2               24                    0          10.062
##   Q70_Last.Click Q70_Page.Submit Q70_Click.Count stress_1 stress_2 stress_3
## 1         54.318          60.887              16        2        4        5
## 2         27.841          28.982              17        4        5        5
## 3         79.053          80.519              18        4        4        5
## 4         77.308          79.068              13        2        4        4
## 5         18.707          20.343              14        4        3        3
## 6         80.372          82.827              18        3        3        5
##   stress_4 stress_5 stress_6 stress_7 stress_8 stress_9 stress_10
## 1        3        3        3        4        3        3         3
## 2        4        3        3        2        2        4         4
## 3        2        1        5        2        2        4         4
## 4        3        4        5        4        2        2         2
## 5        4        3        4        3        3        4         4
## 6        2        3        5        2        1        3         2
##   stress_biascheck stress_bias_dummy Q69_First.Click Q69_Last.Click
## 1               33                 0          10.383        100.428
## 2               36                 0           9.729         43.281
## 3               33                 0          42.213         89.329
## 4               32                 0          43.206        180.767
## 5               35                 0          63.797         76.765
## 6               29                 0          16.412         94.543
##   Q69_Page.Submit Q69_Click.Count marriage1_1 marriage1_2 marriage1_3
## 1         101.287              14          10          25          30
## 2          44.423              13          10          25          35
## 3          91.194              12           1           1          59
## 4         182.932              12           0           0          60
## 5          77.998              13          25          25          25
## 6          95.709              15          13          33          21
##   marriage1_4 marriage2 marriage3 marriage4 marriage5 Q75_First.Click
## 1          35         2        20         1         2          20.229
## 2          30         3        19         1         1          11.100
## 3          39         2        19         1         1          40.807
## 4          40         1        16         1         1          74.778
## 5          25         2        14         3         1          21.347
## 6          33         3        17         1         1          19.366
##   Q75_Last.Click Q75_Page.Submit Q75_Click.Count                     school sex
## 1        164.560         165.870              32                        ACG   2
## 2         60.223          61.354              17                  ACG,Deree   1
## 3        160.366         165.459              23 American College of Greece   1
## 4        155.971         156.974              13 American College of Greece   2
## 5         48.802          49.742              11 American College of Greece   1
## 6        181.747         183.288              25 American College of Greece   2
##   age edu sibling race race_6_TEXT Q82 Q83 income place2 Q80 place    Q81
## 1  20   2       2    1               3  NA      3      2  NA    NA Greece
## 2  23   5       2    1               3  NA      3      2  NA    NA Greece
## 3  23   2       5    1               3  NA      1      2  NA    NA Greece
## 4  22   2   3,5,7    6       Greek   3  NA      1      2  NA    NA Greece
## 5  18   2   3,5,7    1               3  NA      6      2  NA    NA Greece
## 6  23   2     2,4    1               3  NA      1      2  NA    NA Greece
##   Q81_First.Click Q81_Last.Click Q81_Page.Submit Q81_Click.Count
## 1           0.000          0.000           5.781               0
## 2           2.424          2.424           6.621               1
## 3           0.000          0.000           9.294               0
## 4           2.679          2.679           5.803               1
## 5           1.632          1.632           5.500               1
## 6           2.766          2.766           6.995               1
##                                                                                                                              comments
## 1                                                                                                        I have completed this survey
## 2                                                                                                        i have completed this survey
## 3 Didn't know my household income.\nI have completed the last question about disability wrong. I read "not" the moment I pressed ">>"
## 4                                                                                                        I have completed this survey
## 5                                                                                                        i have completed this survey
## 6                                                                                             The question saying "Select" was funny.
##   affiliation response_bias_SUM school_coded
## 1    acgreece                 0     acgreece
## 2    acgreece                 0     acgreece
## 3    acgreece                 0     acgreece
## 4    acgreece                 0     acgreece
## 5    acgreece                 0     acgreece
## 6    acgreece                 0     acgreece
# use the str() command to see what kinds of variables are in your dataframe
str(df)
## 'data.frame':    3182 obs. of  328 variables:
##  $ StartDate            : chr  "12/02/16" "11/16/16" "11/09/16" "11/07/16" ...
##  $ EndDate              : chr  "12/02/16" "11/16/16" "11/09/16" "11/07/16" ...
##  $ Status               : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ Progress             : int  100 100 99 100 100 100 99 99 100 100 ...
##  $ Duration..in.seconds.: int  1839 1467 2185 2904 1229 2068 1656 1839 1160 2134 ...
##  $ Finished             : int  1 1 0 1 1 1 0 0 1 1 ...
##  $ RecordedDate         : chr  "12/2/2016 5:38" "11/16/2016 11:53" "11/16/2016 1:22" "11/7/2016 4:54" ...
##  $ ResponseId           : chr  "R_BJN3bQqi1zUMid3" "R_2TGbiBXmAtxywsD" "R_12G7bIqN2wB2N65" "R_39pldNoon8CePfP" ...
##  $ RecipientLastName    : logi  NA NA NA NA NA NA ...
##  $ RecipientFirstName   : logi  NA NA NA NA NA NA ...
##  $ RecipientEmail       : logi  NA NA NA NA NA NA ...
##  $ ExternalReference    : logi  NA NA NA NA NA NA ...
##  $ DistributionChannel  : chr  "anonymous" "anonymous" "anonymous" "anonymous" ...
##  $ informedconsent      : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ moa1.1_1             : int  4 4 4 4 4 4 4 4 4 3 ...
##  $ moa1.1_2             : int  4 4 4 3 4 3 4 4 4 2 ...
##  $ moa1.1_3             : int  3 4 4 3 4 4 4 4 4 3 ...
##  $ moa1.1_4             : int  2 2 1 1 1 2 3 3 4 1 ...
##  $ moa1.1_5             : int  2 3 1 1 1 3 3 3 4 1 ...
##  $ moa1.1_6             : int  3 3 4 2 3 4 4 4 4 2 ...
##  $ moa1.1_7             : int  2 4 2 1 1 2 4 3 1 3 ...
##  $ moa1.1_8             : int  1 3 3 1 1 1 4 3 2 3 ...
##  $ moa1.1_9             : int  4 3 4 1 4 3 4 4 4 4 ...
##  $ moa1.1_10            : int  3 3 3 1 3 4 3 3 4 3 ...
##  $ moa1.2_1             : int  2 1 2 1 2 1 1 2 2 2 ...
##  $ moa1.2_2             : int  1 1 1 1 1 1 1 2 2 2 ...
##  $ moa1.2_3             : int  2 2 1 1 2 1 2 2 2 2 ...
##  $ moa1.2_4             : int  1 2 1 1 1 1 1 1 1 1 ...
##  $ moa1.2_5             : int  1 1 1 1 3 1 1 1 1 1 ...
##  $ moa1.2_6             : int  1 1 1 1 3 1 1 1 2 2 ...
##  $ moa1.2_7             : int  2 1 2 2 1 1 3 3 1 3 ...
##  $ moa1.2_8             : int  3 1 3 3 1 1 3 3 3 3 ...
##  $ moa1.2_9             : int  3 2 3 2 3 1 3 3 3 3 ...
##  $ moa1.2_10            : int  2 3 3 3 2 3 3 3 1 3 ...
##  $ moa2.1_1             : int  4 3 4 4 4 4 4 4 4 3 ...
##  $ moa2.1_2             : int  4 4 2 2 4 4 4 4 4 3 ...
##  $ moa2.1_3             : int  4 2 2 2 3 4 3 4 4 3 ...
##  $ moa2.1_4             : int  4 4 4 4 4 4 4 4 4 4 ...
##  $ moa2.1_5             : int  3 4 3 3 4 2 4 4 4 3 ...
##  $ moa2.1_6             : int  4 3 3 2 3 4 4 3 4 4 ...
##  $ moa2.1_7             : int  4 2 4 4 4 3 4 4 2 4 ...
##  $ moa2.1_8             : int  4 4 4 2 4 4 3 4 4 4 ...
##  $ moa2.1_9             : int  3 2 3 3 3 4 4 4 4 4 ...
##  $ moa2.1_10            : int  2 1 2 2 3 4 2 4 2 2 ...
##  $ moa2.2_1             : int  2 3 2 2 3 2 2 2 3 3 ...
##  $ moa2.2_2             : int  1 1 1 1 3 1 1 1 1 2 ...
##  $ moa2.2_3             : int  1 2 1 1 3 1 1 1 3 3 ...
##  $ moa2.2_4             : int  3 2 2 2 3 2 2 3 3 3 ...
##  $ moa2.2_5             : int  2 1 1 1 3 1 1 1 2 2 ...
##  $ moa2.2_6             : int  3 2 2 2 2 2 2 2 3 3 ...
##  $ moa2.2_7             : int  3 2 3 2 3 2 1 2 1 3 ...
##  $ moa2.2_8             : int  2 2 1 2 3 1 2 3 2 2 ...
##  $ moa2.2_9             : int  2 2 1 2 2 2 2 2 3 3 ...
##  $ moa2.2_10            : int  1 1 1 1 3 1 1 1 1 2 ...
##  $ adult_Q              : int  1 1 1 1 1 1 1 1 1 2 ...
##  $ MOA_IMP_biascheck    : int  64 62 61 46 62 67 73 74 71 59 ...
##  $ MOA_ach_biascheck    : int  38 33 33 32 47 27 34 39 40 48 ...
##  $ MOA_IMP_dummy        : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ MOA.ACH_dummy        : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ Q65_First.Click      : num  37.1 120 27.7 19.7 12.9 ...
##  $ Q65_Last.Click       : num  308 336 154 297 122 ...
##  $ Q65_Page.Submit      : num  309 338 156 299 122 ...
##  $ Q65_Click.Count      : int  45 58 47 43 46 50 45 42 47 47 ...
##  $ IDEA_1               : int  3 4 4 4 4 3 4 4 4 4 ...
##  $ IDEA_2               : int  4 4 4 4 4 4 3 3 4 4 ...
##  $ IDEA_3               : int  4 4 4 3 3 3 4 3 3 2 ...
##  $ IDEA_4               : int  3 4 4 3 4 3 4 4 2 2 ...
##  $ IDEA_5               : int  4 3 4 4 3 4 3 3 4 4 ...
##  $ IDEA_6               : int  4 4 4 4 3 4 4 2 4 4 ...
##  $ IDEA_7               : int  4 4 3 4 3 3 3 2 3 3 ...
##  $ IDEA_8               : int  4 4 3 4 4 2 3 3 3 4 ...
##  $ IDEA.biascheck       : int  30 31 30 30 28 26 28 24 27 27 ...
##  $ IDEA.bias.dummy      : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ Q66_First.Click      : num  44.7 19.9 23.2 27.5 24 ...
##  $ Q66_Last.Click       : num  86.6 65.2 51.4 172.8 52.2 ...
##  $ Q66_Page.Submit      : num  87.5 67.2 52.4 174.1 53.4 ...
##  $ Q66_Click.Count      : int  11 13 11 9 9 13 9 8 8 9 ...
##  $ politics             : int  2 1 2 8 1 8 4 2 8 4 ...
##  $ party                : int  3 4 8 8 8 8 4 1 3 8 ...
##  $ president            : chr  "" "None, but I was a US Citizen and had a gun next to my head, I would vote for Trump" "Hillary Clinton" "Hillary Clinton" ...
##  $ Q74_First.Click      : num  13.1 4.9 34.9 66.9 23.6 ...
##  $ Q74_Last.Click       : num  40.4 28.1 48.4 119.2 32.2 ...
##  $ Q74_Page.Submit      : num  46.4 55.1 56.4 135.3 35.3 ...
##  $ Q74_Click.Count      : int  2 6 4 4 4 6 3 3 3 3 ...
##  $ swb_1                : int  4 3 1 5 2 4 4 5 5 5 ...
##  $ swb_2                : int  6 4 2 6 5 4 4 5 5 4 ...
##  $ swb_3                : int  5 5 2 6 5 6 5 6 5 6 ...
##  $ swb_4                : int  5 5 2 5 3 5 4 5 5 4 ...
##  $ swb_5                : int  3 4 2 6 2 1 1 6 5 6 ...
##  $ swb_6                : int  3 4 2 3 5 4 4 6 5 4 ...
##  $ Q67_First.Click      : num  9.63 8.61 37.66 13.59 6.8 ...
##  $ Q67_Last.Click       : num  40.4 29.1 53.2 55.2 22.2 ...
##  $ Q67_Page.Submit      : num  41.2 30 54.6 56.1 23.1 ...
##  $ Q67_Click.Count      : int  7 7 9 7 7 7 7 7 6 13 ...
##  $ mindful_1            : int  4 2 2 2 4 1 5 3 3 5 ...
##  $ mindful_2            : int  2 2 3 2 5 4 6 2 3 6 ...
##  $ mindful_3            : int  2 2 1 1 3 3 5 4 4 4 ...
##  $ mindful_4            : int  2 1 2 2 2 3 4 2 3 5 ...
##  $ mindful_5            : int  4 3 3 2 4 5 6 2 3 6 ...
##   [list output truncated]

Subsetting Data

# use the subset() command to select which columns to keep in your dataframe
d<- subset(df, select=c(politics, income, belong_1, belong_2, belong_3, belong_4, belong_5, belong_6, belong_7, belong_8, belong_9, belong_10, support_1, support_2, support_3, support_4, support_5, support_6, support_7, support_8, support_9, support_10, support_11, support_12, SocMedia_1, SocMedia_2, SocMedia_3, SocMedia_4, SocMedia_5, SocMedia_6, SocMedia_7, SocMedia_8, SocMedia_9, SocMedia_10, SocMedia_11, stress_1, stress_2, stress_3, stress_4, stress_5, stress_6, stress_7, stress_8, stress_9, stress_10))

Basic Data Checking

Checking Values

# use the map() command to view tables for all of your columns/variables at once
d %>%
  map(table, useNA = "always")
## $politics
## 
##    1    2    3    4    5    6    7    8 <NA> 
##  235  772  373  568  308  332   57  532    5 
## 
## $income
## 
##    1    2    3    4    5    6    7    8    9 <NA> 
##  860  518  361  344  302  236  389  140    7   25 
## 
## $belong_1
## 
##    1    2    3    4    5 <NA> 
##  225  841  626  981  505    4 
## 
## $belong_2
## 
##    1    2    3    4    5 <NA> 
##  276  562  727 1080  533    4 
## 
## $belong_3
## 
##    1    2    3    4    5 <NA> 
##  413  939  672  848  306    4 
## 
## $belong_4
## 
##    1    2    3    4    5 <NA> 
##   91  188  321 1217 1362    3 
## 
## $belong_5
## 
##    1    2    3    4    5 <NA> 
##  132  200  636 1390  821    3 
## 
## $belong_6
## 
##    1    2    3    4    5 <NA> 
##  381  720  800  738  540    3 
## 
## $belong_7
## 
##    1    2    3    4    5 <NA> 
##  428  942  580  809  418    5 
## 
## $belong_8
## 
##    1    2    3    4    5 <NA> 
##  266  558  743 1081  530    4 
## 
## $belong_9
## 
##    1    2    3    4    5 <NA> 
##  279  572  730 1164  433    4 
## 
## $belong_10
## 
##    1    2    3    4    5 <NA> 
##  410  760  637  939  431    5 
## 
## $support_1
## 
##    1    2    3    4    5    6    7 <NA> 
##  128  148  192  307  449  696 1258    4 
## 
## $support_2
## 
##    1    2    3    4    5    6    7 <NA> 
##  151  131  156  283  410  693 1354    4 
## 
## $support_3
## 
##    1    2    3    4    5    6    7 <NA> 
##   87   92  132  211  427  906 1325    2 
## 
## $support_4
## 
##    1    2    3    4    5    6    7 <NA> 
##  164  155  235  296  568  748 1014    2 
## 
## $support_5
## 
##    1    2    3    4    5    6    7 <NA> 
##  141  132  153  287  393  657 1416    3 
## 
## $support_6
## 
##    1    2    3    4    5    6    7 <NA> 
##   50  103  151  360  673  997  845    3 
## 
## $support_7
## 
##    1    2    3    4    5    6    7 <NA> 
##   71  110  166  333  679  978  842    3 
## 
## $support_8
## 
##    1    2    3    4    5    6    7 <NA> 
##  199  187  298  317  632  695  851    3 
## 
## $support_9
## 
##    1    2    3    4    5    6    7 <NA> 
##   68   65  133  213  534  994 1172    3 
## 
## $support_10
## 
##    1    2    3    4    5    6    7 <NA> 
##  124  115  137  282  359  691 1471    3 
## 
## $support_11
## 
##    1    2    3    4    5    6    7 <NA> 
##   89   81  126  234  542  921 1186    3 
## 
## $support_12
## 
##    1    2    3    4    5    6    7 <NA> 
##   84   94  157  255  646  980  964    2 
## 
## $SocMedia_1
## 
##    1    2    3    4    5 <NA> 
##  302  599 1136  833  308    4 
## 
## $SocMedia_2
## 
##    1    2    3    4    5 <NA> 
##  581  832  820  662  284    3 
## 
## $SocMedia_3
## 
##    1    2    3    4    5 <NA> 
##  148  298  808 1164  761    3 
## 
## $SocMedia_4
## 
##    1    2    3    4    5 <NA> 
##  348  638  830  880  483    3 
## 
## $SocMedia_5
## 
##    1    2    3    4    5 <NA> 
##  386  910 1032  602  249    3 
## 
## $SocMedia_6
## 
##    1    2    3    4    5 <NA> 
##  267  371  820 1042  679    3 
## 
## $SocMedia_7
## 
##    1    2    3    4    5 <NA> 
##  318  433  816  956  654    5 
## 
## $SocMedia_8
## 
##    1    2    3    4    5 <NA> 
##  892  978  684  414  210    4 
## 
## $SocMedia_9
## 
##    1    2    3    4    5 <NA> 
##  414  669 1009  776  310    4 
## 
## $SocMedia_10
## 
##    1    2    3    4    5 <NA> 
##  188  323  879 1116  673    3 
## 
## $SocMedia_11
## 
##    1    2    3    4    5 <NA> 
##  313  572  914  871  509    3 
## 
## $stress_1
## 
##    1    2    3    4    5 <NA> 
##  147  656 1331  775  268    5 
## 
## $stress_2
## 
##    1    2    3    4    5 <NA> 
##  209  665 1074  786  443    5 
## 
## $stress_3
## 
##    1    2    3    4    5 <NA> 
##   31  128  639 1037 1342    5 
## 
## $stress_4
## 
##    1    2    3    4    5 <NA> 
##   68  359 1217 1098  434    6 
## 
## $stress_5
## 
##    1    2    3    4    5 <NA> 
##  119  523 1482  857  196    5 
## 
## $stress_6
## 
##    1    2    3    4    5 <NA> 
##  221  826 1164  662  304    5 
## 
## $stress_7
## 
##    1    2    3    4    5 <NA> 
##   99  461 1395 1007  215    5 
## 
## $stress_8
## 
##    1    2    3    4    5 <NA> 
##  135  572 1340  948  181    6 
## 
## $stress_9
## 
##    1    2    3    4    5 <NA> 
##  175  646 1123  846  387    5 
## 
## $stress_10
## 
##    1    2    3    4    5 <NA> 
##  295  763 1037  660  422    5

Recoding Variables

# use the table() command to view a table of a single variable at a time 
table(d$belong_1, useNA = "always")
## 
##    1    2    3    4    5 <NA> 
##  225  841  626  981  505    4
# use the below code to recode a variable
d$belong_1_rc[d$belong_1 ==1] <- 5
d$belong_1_rc[d$belong_1 ==2] <- 4
d$belong_1_rc[d$belong_1 ==3] <- 3
d$belong_1_rc[d$belong_1 ==4] <- 2
d$belong_1_rc[d$belong_1 ==5] <- 1

table(d$belong_1_rc, useNA = "always")
## 
##    1    2    3    4    5 <NA> 
##  505  981  626  841  225    4
table(d$belong_3, useNA = "always")
## 
##    1    2    3    4    5 <NA> 
##  413  939  672  848  306    4
d$belong_3_rc[d$belong_3 ==1] <- 5
d$belong_3_rc[d$belong_3 ==2] <- 4
d$belong_3_rc[d$belong_3 ==3] <- 3
d$belong_3_rc[d$belong_3 ==4] <- 2
d$belong_3_rc[d$belong_3 ==5] <- 1

table(d$belong_3_rc, useNA = "always")
## 
##    1    2    3    4    5 <NA> 
##  306  848  672  939  413    4
table(d$belong_7, useNA = "always")
## 
##    1    2    3    4    5 <NA> 
##  428  942  580  809  418    5
d$belong_7_rc[d$belong_7 ==1] <- 5
d$belong_7_rc[d$belong_7 ==2] <- 4
d$belong_7_rc[d$belong_7 ==3] <- 3
d$belong_7_rc[d$belong_7 ==4] <- 2
d$belong_7_rc[d$belong_7 ==5] <- 1

table(d$belong_7_rc, useNA = "always")
## 
##    1    2    3    4    5 <NA> 
##  418  809  580  942  428    5
table(d$stress_4, useNA = "always")
## 
##    1    2    3    4    5 <NA> 
##   68  359 1217 1098  434    6
d$stress_4_rc[d$stress_4 == 1] <- 5
d$stress_4_rc[d$stress_4 == 2] <- 4
d$stress_4_rc[d$stress_4 == 3] <- 3
d$stress_4_rc[d$stress_4 == 4] <- 2
d$stress_4_rc[d$stress_4 == 5] <- 1

table(d$stress_4_rc, useNA = "always")
## 
##    1    2    3    4    5 <NA> 
##  434 1098 1217  359   68    6
table(d$stress_5, useNA = "always")
## 
##    1    2    3    4    5 <NA> 
##  119  523 1482  857  196    5
d$stress_5_rc[d$stress_5 == 1] <- 5
d$stress_5_rc[d$stress_5 == 2] <- 4
d$stress_5_rc[d$stress_5 == 3] <- 3
d$stress_5_rc[d$stress_5 == 4] <- 2
d$stress_5_rc[d$stress_5 == 5] <- 1

table(d$stress_5_rc, useNA = "always")
## 
##    1    2    3    4    5 <NA> 
##  196  857 1482  523  119    5
table(d$stress_7, useNA = "always")
## 
##    1    2    3    4    5 <NA> 
##   99  461 1395 1007  215    5
d$stress_7_rc[d$stress_7 == 1] <- 5
d$stress_7_rc[d$stress_7 == 2] <- 4
d$stress_7_rc[d$stress_7 == 3] <- 3
d$stress_7_rc[d$stress_7 == 4] <- 2
d$stress_7_rc[d$stress_7 == 5] <- 1

table(d$stress_7_rc, useNA = "always")
## 
##    1    2    3    4    5 <NA> 
##  215 1007 1395  461   99    5
table(d$stress_8, useNA = "always")
## 
##    1    2    3    4    5 <NA> 
##  135  572 1340  948  181    6
d$stress_8_rc[d$stress_8 == 1] <- 5
d$stress_8_rc[d$stress_8 == 2] <- 4
d$stress_8_rc[d$stress_8 == 3] <- 3
d$stress_8_rc[d$stress_8 == 4] <- 2
d$stress_8_rc[d$stress_8 == 5] <- 1

table(d$stress_8_rc, useNA = "always")
## 
##    1    2    3    4    5 <NA> 
##  181  948 1340  572  135    6
# afterwards, use the table() command to check your new variable
table(d$stress_8_rc, useNA = "always")
## 
##    1    2    3    4    5 <NA> 
##  181  948 1340  572  135    6

Factor scores/composite variables

# use the str() command to check that your recoded variable is numeric so you can use mathematical operators on it 
str(d)
## 'data.frame':    3182 obs. of  52 variables:
##  $ politics   : int  2 1 2 8 1 8 4 2 8 4 ...
##  $ income     : int  3 3 1 1 6 1 2 3 7 1 ...
##  $ belong_1   : int  4 2 4 3 4 2 2 3 4 4 ...
##  $ belong_2   : int  2 3 4 4 3 3 5 4 3 3 ...
##  $ belong_3   : int  4 1 2 1 3 2 1 2 3 3 ...
##  $ belong_4   : int  4 5 5 5 4 5 4 5 3 4 ...
##  $ belong_5   : int  4 4 4 4 4 4 5 4 4 3 ...
##  $ belong_6   : int  2 4 4 5 5 5 4 4 2 1 ...
##  $ belong_7   : int  5 2 2 2 1 1 2 1 5 3 ...
##  $ belong_8   : int  2 4 3 4 3 4 4 3 3 2 ...
##  $ belong_9   : int  4 5 4 4 2 4 4 4 4 1 ...
##  $ belong_10  : int  3 4 4 4 3 4 4 2 4 3 ...
##  $ support_1  : int  7 7 6 6 6 7 7 6 7 6 ...
##  $ support_2  : int  4 7 6 6 6 7 7 7 5 6 ...
##  $ support_3  : int  6 7 5 7 5 6 4 6 6 2 ...
##  $ support_4  : int  5 6 2 3 5 6 3 5 6 1 ...
##  $ support_5  : int  6 7 7 7 6 7 7 7 5 4 ...
##  $ support_6  : int  6 6 5 6 6 2 4 7 6 6 ...
##  $ support_7  : int  7 6 5 5 7 2 4 7 7 7 ...
##  $ support_8  : int  7 7 3 4 6 1 3 3 6 2 ...
##  $ support_9  : int  7 7 6 6 6 1 5 7 7 7 ...
##  $ support_10 : int  4 7 6 6 6 7 7 6 6 6 ...
##  $ support_11 : int  6 7 5 6 7 6 4 5 5 2 ...
##  $ support_12 : int  7 7 6 5 6 2 5 7 6 4 ...
##  $ SocMedia_1 : int  4 3 3 4 3 1 3 5 3 5 ...
##  $ SocMedia_2 : int  2 2 3 2 3 1 3 5 2 2 ...
##  $ SocMedia_3 : int  5 4 4 5 5 2 3 5 4 5 ...
##  $ SocMedia_4 : int  3 2 2 2 2 1 3 4 5 3 ...
##  $ SocMedia_5 : int  5 1 3 2 2 1 2 3 4 2 ...
##  $ SocMedia_6 : int  5 1 4 4 4 1 4 4 4 1 ...
##  $ SocMedia_7 : int  5 1 4 4 4 2 4 4 2 1 ...
##  $ SocMedia_8 : int  4 1 2 1 2 1 1 2 3 1 ...
##  $ SocMedia_9 : int  5 2 3 3 4 1 4 3 4 3 ...
##  $ SocMedia_10: int  5 4 3 4 4 1 5 5 3 3 ...
##  $ SocMedia_11: int  4 2 3 4 4 1 5 3 3 3 ...
##  $ stress_1   : int  2 4 4 2 4 3 3 3 3 2 ...
##  $ stress_2   : int  4 5 4 4 3 3 4 2 3 3 ...
##  $ stress_3   : int  5 5 5 4 3 5 5 3 3 3 ...
##  $ stress_4   : int  3 4 2 3 4 2 3 4 3 4 ...
##  $ stress_5   : int  3 3 1 4 3 3 3 4 3 3 ...
##  $ stress_6   : int  3 3 5 5 4 5 4 3 3 4 ...
##  $ stress_7   : int  4 2 2 4 3 2 3 4 3 4 ...
##  $ stress_8   : int  3 2 2 2 3 1 2 4 3 4 ...
##  $ stress_9   : int  3 4 4 2 4 3 3 2 3 2 ...
##  $ stress_10  : int  3 4 4 2 4 2 2 1 2 3 ...
##  $ belong_1_rc: num  2 4 2 3 2 4 4 3 2 2 ...
##  $ belong_3_rc: num  2 5 4 5 3 4 5 4 3 3 ...
##  $ belong_7_rc: num  1 4 4 4 5 5 4 5 1 3 ...
##  $ stress_4_rc: num  3 2 4 3 2 4 3 2 3 2 ...
##  $ stress_5_rc: num  3 3 5 2 3 3 3 2 3 3 ...
##  $ stress_7_rc: num  2 4 4 2 3 4 3 2 3 2 ...
##  $ stress_8_rc: num  3 4 4 4 3 5 4 2 3 2 ...
# create your composite variable by adding the individual items and dividing by the total number of items
d$belong <- (d$belong_1_rc + d$belong_2 + d$belong_3_rc + d$belong_4 + d$belong_5 + d$belong_6 + d$belong_7_rc + d$belong_8 + d$belong_9 + d$belong_10)/10

d$support <- (d$support_1 + d$support_2 + d$support_3 + d$support_4 + d$support_5 + d$support_6 + d$support_7 + d$support_8 + d$support_9 + d$support_10 + d$support_11 + d$support_12)/12

d$SocMedia <- (d$SocMedia_1 + d$SocMedia_2 + d$SocMedia_3 + d$SocMedia_4 + d$SocMedia_5 + d$SocMedia_6 + d$SocMedia_7 + d$SocMedia_8 + d$SocMedia_9 + d$SocMedia_10 + d$SocMedia_11)/11

d$stress <- (d$stress_1 + d$stress_2 + d$stress_3 + d$stress_4_rc + d$stress_5_rc + d$stress_6 + d$stress_7_rc + d$stress_8_rc + d$stress_9 + d$stress_10)/10

Exporting Data

# use the subset() command to finalize your current dataframe
# in the version of the subset() command below, a dash is added to the "c" argument so that instead of keeping the columns listed in the parentheses, R will drop them instead
d2 <- subset(d, select=-c(stress_1, stress_2, stress_3, stress_4, stress_4_rc, stress_5, stress_5_rc, stress_6, stress_7, stress_7_rc, stress_8, stress_8_rc, stress_9, stress_10, SocMedia_1, SocMedia_2, SocMedia_3, SocMedia_4, SocMedia_5, SocMedia_6, SocMedia_7, SocMedia_8, SocMedia_9, SocMedia_10, SocMedia_11, support_1, support_2, support_3, support_4, support_5, support_6, support_7, support_8, support_9, support_10, support_11, support_12, belong_1, belong_1_rc, belong_2, belong_3, belong_3_rc, belong_4, belong_5, belong_6, belong_7_rc, belong_7, belong_8, belong_9, belong_10))

d2 <- subset(d2, select=c(income, politics, stress, SocMedia, support, belong))

#use the write.csv() command to export your finalized dataframe
write.csv(d2, file="cashw.csv", row.names = F)
newd <- read.csv(file="cashw.csv", header=T)

Basic Statistics

Import Cleaned Data

d <- read.csv(file="cashw.csv", header=T)

Check data

Formatting

head(d2)
##   income politics stress SocMedia  support belong
## 1      3        2    3.1 4.272727 6.000000    2.6
## 2      3        1    3.8 2.090909 6.750000    4.2
## 3      1        2    4.3 3.090909 5.166667    3.8
## 4      1        8    3.0 3.181818 5.583333    4.2
## 5      6        1    3.3 3.363636 6.000000    3.4
## 6      1        8    3.7 1.181818 4.500000    4.2
str(d2)
## 'data.frame':    3182 obs. of  6 variables:
##  $ income  : int  3 3 1 1 6 1 2 3 7 1 ...
##  $ politics: int  2 1 2 8 1 8 4 2 8 4 ...
##  $ stress  : num  3.1 3.8 4.3 3 3.3 3.7 3.4 2.2 2.9 2.6 ...
##  $ SocMedia: num  4.27 2.09 3.09 3.18 3.36 ...
##  $ support : num  6 6.75 5.17 5.58 6 ...
##  $ belong  : num  2.6 4.2 3.8 4.2 3.4 4.2 4.3 3.8 2.9 2.5 ...
# use as.factor() command to make sure your categorical variables are recognized as such
d2$politics <- as.factor(d$politics)
d2$income <- as.factor(d$income)

Univariate Formality

table(d2$politics)
## 
##   1   2   3   4   5   6   7   8 
## 235 772 373 568 308 332  57 532
describe(d2)
##           vars    n mean   sd median trimmed  mad min max range  skew kurtosis
## income*      1 3157 3.54 2.30   3.00    3.37 2.97 1.0   9   8.0  0.47    -1.12
## politics*    2 3177 4.20 2.25   4.00    4.10 2.97 1.0   8   7.0  0.43    -1.03
## stress       3 3175 3.06 0.66   3.10    3.06 0.59 1.0   5   4.0  0.04    -0.04
## SocMedia     4 3175 3.13 0.78   3.18    3.16 0.67 1.0   5   4.0 -0.31     0.26
## support      5 3176 5.53 1.13   5.75    5.65 0.99 1.0   7   6.0 -1.10     1.39
## belong       6 3175 3.30 0.73   3.30    3.32 0.74 1.1   5   3.9 -0.28    -0.23
##             se
## income*   0.04
## politics* 0.04
## stress    0.01
## SocMedia  0.01
## support   0.02
## belong    0.01

Histograms

# use the hist() command to create a histogram for your continuous variables
hist(d2$belong)

hist(d2$support)

hist(d2$SocMedia)

hist(d2$stress)

# use the table() command to create a table for your categorical variables 
table(d2$politics)
## 
##   1   2   3   4   5   6   7   8 
## 235 772 373 568 308 332  57 532
table(d2$income)
## 
##   1   2   3   4   5   6   7   8   9 
## 860 518 361 344 302 236 389 140   7

Missing Data

# use the gg_miss_upset() command to visualize your missing data
gg_miss_upset(d2, nsets = "6")

# create a new dataframe with only your complete cases/observations
d3 <- na.omit(d2)

Crosstabs & Scatterplots

Crosstabs

table(d2$politics)
## 
##   1   2   3   4   5   6   7   8 
## 235 772 373 568 308 332  57 532
# use the cross_cases() command to create a crosstab of your categorical variables
cross_cases(d3, income, politics)
 politics 
 1   2   3   4   5   6   7   8 
 income 
   1  48 195 82 156 71 75 11 210
   2  50 135 57 94 48 39 6 88
   3  27 94 42 61 35 32 5 64
   4  33 78 51 79 23 33 6 40
   5  21 66 45 52 36 31 2 46
   6  18 64 35 36 31 19 9 24
   7  22 93 43 62 46 72 12 38
   8  10 41 15 20 15 25 5 8
   9  1 1 2 3
   #Total cases  229 767 370 561 307 329 56 518

Scatterplots

# use the plot() command to create scatterplots of your continuous variables
plot(d3$belong, d3$stress,
     main="scatterplot of the need to belong and amount of stress",
     xlab = "need to belong",
     ylab = "amount of stress")

plot(d2$support, d2$SocMedia,
     main="scatterplot of the amount of perceived social support and social media prescence",
     xlab = "perceived social support",
     ylab = "social media prescence")

Boxplots

# use the boxplot() command to create boxplots of your continuous and categorical variables
boxplot(data=d3,
politics~belong,
       main="politics affiliation by need to belong score",
      xlab = "politics affiliation",
      ylab = "need to belong scale")

boxplot(data=d3, support~income,
        main="perceived social support by income",
        xlab = "perceived social support",
        ylab = "income scale")

1.Do your continuous variables meet the criteria for univariate normality? Yes, my continuous variables meet the criteria for univariate normality. Stress: skew: .03 kurtosis: -.04 Belong: skew: -.29 kurtosis: -.23 SocMedia: skew: -.32 kurtosis: .27 Support: skew: -1.07 kurtosis: 1.29

Do you have any missing data? I was missing 45 answers. My new total sample size is 3137. This is due to item non response, the participants missed this portion.