This manual is an R cheatsheet for Psychology students. It explains how to complete many tasks psychologists commonly do. Click through the table of contents to quickly find the task you need. Watch this video to learn how to install R and RStudio:
Haven contains functions that lets R import SPSS, SAS, Stata, and other foreign files.
Documentation can be viewed here
# Check if haven is already installed and if it is, load it.
if (!require(haven)){
# If it's not intalled, then tell R to install it.
install.packages("haven", dependencies = TRUE)
# Once it's installed, tell R to load it.
library(haven)
}
Tidyverse contains many functions useful to cleaning, tidying, and manipulating data
Documentation can be viewed here
if (!require(tidyverse)){
install.packages("tidyverse", dependencies = TRUE)
library(tidyverse)
}
Summarytools provide useful functions for summarizing and visualizing data
Documentation can be viewed here
if (!require(summarytools)){
install.packages("summarytools", dependencies = TRUE)
require(summarytools)
}
Summarytools provide useful functions for summarizing and visualizing data
Documentation can be viewed here
if (!require(psych)){
install.packages("psych", dependencies = TRUE)
require(psych)
}
Loading required package: psych
Attaching package: ‘psych’
The following objects are masked from ‘package:ggplot2’:
%+%, alpha
quick and easy correlations
Documentation can be viewed here
if (!require(corrr)){
install.packages("corrr", dependencies = TRUE)
require(corrr)
}
Loading required package: corrr
Warning: there is no package called ‘corrr’Installing package into ‘/cloud/lib/x86_64-pc-linux-gnu-library/4.3’
(as ‘lib’ is unspecified)
also installing the dependencies ‘iterators’, ‘permute’, ‘ca’, ‘foreach’, ‘gclus’, ‘qap’, ‘registry’, ‘TSP’, ‘vegan’, ‘plogr’, ‘config’, ‘globals’, ‘ggrepel’, ‘seriation’, ‘RSQLite’, ‘sparklyr’
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/iterators_1.0.14.tar.gz'
Content type 'application/x-gzip' length 345417 bytes (337 KB)
==================================================
downloaded 337 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/permute_0.9-7.tar.gz'
Content type 'application/x-gzip' length 219635 bytes (214 KB)
==================================================
downloaded 214 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/ca_0.71.1.tar.gz'
Content type 'application/x-gzip' length 241189 bytes (235 KB)
==================================================
downloaded 235 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/foreach_1.5.2.tar.gz'
Content type 'application/x-gzip' length 138106 bytes (134 KB)
==================================================
downloaded 134 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/gclus_1.3.2.tar.gz'
Content type 'application/x-gzip' length 414943 bytes (405 KB)
==================================================
downloaded 405 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/qap_0.1-2.tar.gz'
Content type 'application/x-gzip' length 466661 bytes (455 KB)
==================================================
downloaded 455 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/registry_0.5-1.tar.gz'
Content type 'application/x-gzip' length 194096 bytes (189 KB)
==================================================
downloaded 189 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/TSP_1.2-4.tar.gz'
Content type 'application/x-gzip' length 688671 bytes (672 KB)
==================================================
downloaded 672 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/vegan_2.6-4.tar.gz'
Content type 'application/x-gzip' length 3097932 bytes (3.0 MB)
==================================================
downloaded 3.0 MB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/plogr_0.2.0.tar.gz'
Content type 'application/x-gzip' length 12883 bytes (12 KB)
==================================================
downloaded 12 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/config_0.3.2.tar.gz'
Content type 'application/x-gzip' length 102014 bytes (99 KB)
==================================================
downloaded 99 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/globals_0.16.3.tar.gz'
Content type 'application/x-gzip' length 107519 bytes (104 KB)
==================================================
downloaded 104 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/ggrepel_0.9.5.tar.gz'
Content type 'application/x-gzip' length 274922 bytes (268 KB)
==================================================
downloaded 268 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/seriation_1.5.4.tar.gz'
Content type 'application/x-gzip' length 1329183 bytes (1.3 MB)
==================================================
downloaded 1.3 MB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/RSQLite_2.3.5.tar.gz'
Content type 'application/x-gzip' length 1257715 bytes (1.2 MB)
==================================================
downloaded 1.2 MB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/sparklyr_1.8.4.tar.gz'
Content type 'application/x-gzip' length 6193966 bytes (5.9 MB)
==================================================
downloaded 5.9 MB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/corrr_0.4.4.tar.gz'
Content type 'application/x-gzip' length 480681 bytes (469 KB)
==================================================
downloaded 469 KB
* installing *binary* package ‘iterators’ ...
* DONE (iterators)
* installing *binary* package ‘permute’ ...
* DONE (permute)
* installing *binary* package ‘ca’ ...
* DONE (ca)
* installing *binary* package ‘gclus’ ...
* DONE (gclus)
* installing *binary* package ‘qap’ ...
* DONE (qap)
* installing *binary* package ‘registry’ ...
* DONE (registry)
* installing *binary* package ‘plogr’ ...
* DONE (plogr)
* installing *binary* package ‘config’ ...
* DONE (config)
* installing *binary* package ‘globals’ ...
* DONE (globals)
* installing *binary* package ‘ggrepel’ ...
* DONE (ggrepel)
* installing *binary* package ‘foreach’ ...
* DONE (foreach)
* installing *binary* package ‘vegan’ ...
* DONE (vegan)
* installing *binary* package ‘RSQLite’ ...
* DONE (RSQLite)
* installing *binary* package ‘sparklyr’ ...
* DONE (sparklyr)
* installing *binary* package ‘TSP’ ...
* DONE (TSP)
* installing *binary* package ‘seriation’ ...
* DONE (seriation)
* installing *binary* package ‘corrr’ ...
* DONE (corrr)
The downloaded source packages are in
‘/tmp/RtmpwBrd26/downloaded_packages’
Loading required package: corrr
quick and easy correlations
Documentation can be viewed here
if (!require(GGally)){
install.packages("GGally", dependencies = TRUE)
require(GGally)
}
Loading required package: GGally
Warning: there is no package called ‘GGally’Installing package into ‘/cloud/lib/x86_64-pc-linux-gnu-library/4.3’
(as ‘lib’ is unspecified)
also installing the dependencies ‘proxy’, ‘DEoptimR’, ‘htmlwidgets’, ‘coda’, ‘patchwork’, ‘e1071’, ‘pcaPP’, ‘robustbase’, ‘som’, ‘lars’, ‘pls’, ‘mclust’, ‘sp’, ‘tweenr’, ‘polyclip’, ‘gridExtra’, ‘htmlTable’, ‘viridis’, ‘Formula’, ‘statnet.common’, ‘rJava’, ‘brew’, ‘hunspell’, ‘estimability’, ‘mvtnorm’, ‘ggstats’, ‘broom.helpers’, ‘chemometrics’, ‘geosphere’, ‘ggforce’, ‘Hmisc’, ‘igraph’, ‘intergraph’, ‘labelled’, ‘maps’, ‘mapproj’, ‘network’, ‘scagnostics’, ‘sna’, ‘roxygen2’, ‘crosstalk’, ‘spelling’, ‘emmeans’, ‘vdiffr’
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/proxy_0.4-27.tar.gz'
Content type 'application/x-gzip' length 174312 bytes (170 KB)
==================================================
downloaded 170 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/DEoptimR_1.1-3.tar.gz'
Content type 'application/x-gzip' length 72144 bytes (70 KB)
==================================================
downloaded 70 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/htmlwidgets_1.6.4.tar.gz'
Content type 'application/x-gzip' length 813400 bytes (794 KB)
==================================================
downloaded 794 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/coda_0.19-4.1.tar.gz'
Content type 'application/x-gzip' length 322550 bytes (314 KB)
==================================================
downloaded 314 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/patchwork_1.2.0.tar.gz'
Content type 'application/x-gzip' length 3294945 bytes (3.1 MB)
==================================================
downloaded 3.1 MB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/e1071_1.7-14.tar.gz'
Content type 'application/x-gzip' length 590555 bytes (576 KB)
==================================================
downloaded 576 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/pcaPP_2.0-4.tar.gz'
Content type 'application/x-gzip' length 368306 bytes (359 KB)
==================================================
downloaded 359 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/robustbase_0.99-2.tar.gz'
Content type 'application/x-gzip' length 3085310 bytes (2.9 MB)
==================================================
downloaded 2.9 MB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/som_0.3-5.1.tar.gz'
Content type 'application/x-gzip' length 236465 bytes (230 KB)
==================================================
downloaded 230 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/lars_1.3.tar.gz'
Content type 'application/x-gzip' length 226433 bytes (221 KB)
==================================================
downloaded 221 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/pls_2.8-3.tar.gz'
Content type 'application/x-gzip' length 1180576 bytes (1.1 MB)
==================================================
downloaded 1.1 MB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/mclust_6.1.tar.gz'
Content type 'application/x-gzip' length 4101265 bytes (3.9 MB)
==================================================
downloaded 3.9 MB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/sp_2.1-3.tar.gz'
Content type 'application/x-gzip' length 2092096 bytes (2.0 MB)
==================================================
downloaded 2.0 MB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/tweenr_2.0.3.tar.gz'
Content type 'application/x-gzip' length 490118 bytes (478 KB)
==================================================
downloaded 478 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/polyclip_1.10-6.tar.gz'
Content type 'application/x-gzip' length 117017 bytes (114 KB)
==================================================
downloaded 114 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/gridExtra_2.3.tar.gz'
Content type 'application/x-gzip' length 1107031 bytes (1.1 MB)
==================================================
downloaded 1.1 MB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/htmlTable_2.4.2.tar.gz'
Content type 'application/x-gzip' length 410489 bytes (400 KB)
==================================================
downloaded 400 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/viridis_0.6.5.tar.gz'
Content type 'application/x-gzip' length 3012028 bytes (2.9 MB)
==================================================
downloaded 2.9 MB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/Formula_1.2-5.tar.gz'
Content type 'application/x-gzip' length 158353 bytes (154 KB)
==================================================
downloaded 154 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/statnet.common_4.9.0.tar.gz'
Content type 'application/x-gzip' length 262660 bytes (256 KB)
==================================================
downloaded 256 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/rJava_1.0-11.tar.gz'
Content type 'application/x-gzip' length 969529 bytes (946 KB)
==================================================
downloaded 946 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/brew_1.0-10.tar.gz'
Content type 'application/x-gzip' length 75893 bytes (74 KB)
==================================================
downloaded 74 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/hunspell_3.0.3.tar.gz'
Content type 'application/x-gzip' length 1163549 bytes (1.1 MB)
==================================================
downloaded 1.1 MB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/estimability_1.5.tar.gz'
Content type 'application/x-gzip' length 48270 bytes (47 KB)
==================================================
downloaded 47 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/mvtnorm_1.2-4.tar.gz'
Content type 'application/x-gzip' length 746121 bytes (728 KB)
==================================================
downloaded 728 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/ggstats_0.5.1.tar.gz'
Content type 'application/x-gzip' length 855079 bytes (835 KB)
==================================================
downloaded 835 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/broom.helpers_1.14.0.tar.gz'
Content type 'application/x-gzip' length 528659 bytes (516 KB)
==================================================
downloaded 516 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/chemometrics_1.4.4.tar.gz'
Content type 'application/x-gzip' length 4108257 bytes (3.9 MB)
==================================================
downloaded 3.9 MB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/geosphere_1.5-18.tar.gz'
Content type 'application/x-gzip' length 1025423 bytes (1001 KB)
==================================================
downloaded 1001 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/ggforce_0.4.2.tar.gz'
Content type 'application/x-gzip' length 1847699 bytes (1.8 MB)
==================================================
downloaded 1.8 MB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/Hmisc_5.1-2.tar.gz'
Content type 'application/x-gzip' length 3519023 bytes (3.4 MB)
==================================================
downloaded 3.4 MB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/igraph_2.0.3.tar.gz'
Content type 'application/x-gzip' length 5423508 bytes (5.2 MB)
==================================================
downloaded 5.2 MB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/intergraph_2.0-4.tar.gz'
Content type 'application/x-gzip' length 144175 bytes (140 KB)
==================================================
downloaded 140 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/labelled_2.12.0.tar.gz'
Content type 'application/x-gzip' length 308598 bytes (301 KB)
==================================================
downloaded 301 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/maps_3.4.2.tar.gz'
Content type 'application/x-gzip' length 3096037 bytes (3.0 MB)
==================================================
downloaded 3.0 MB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/mapproj_1.2.11.tar.gz'
Content type 'application/x-gzip' length 50477 bytes (49 KB)
==================================================
downloaded 49 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/network_1.18.2.tar.gz'
Content type 'application/x-gzip' length 808227 bytes (789 KB)
==================================================
downloaded 789 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/scagnostics_0.2-6.tar.gz'
Content type 'application/x-gzip' length 73438 bytes (71 KB)
==================================================
downloaded 71 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/sna_2.7-2.tar.gz'
Content type 'application/x-gzip' length 1249197 bytes (1.2 MB)
==================================================
downloaded 1.2 MB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/roxygen2_7.3.1.tar.gz'
Content type 'application/x-gzip' length 714686 bytes (697 KB)
==================================================
downloaded 697 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/crosstalk_1.2.1.tar.gz'
Content type 'application/x-gzip' length 406745 bytes (397 KB)
==================================================
downloaded 397 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/spelling_2.3.0.tar.gz'
Content type 'application/x-gzip' length 54221 bytes (52 KB)
==================================================
downloaded 52 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/emmeans_1.10.0.tar.gz'
Content type 'application/x-gzip' length 2153219 bytes (2.1 MB)
==================================================
downloaded 2.1 MB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/vdiffr_1.0.7.tar.gz'
Content type 'application/x-gzip' length 154266 bytes (150 KB)
==================================================
downloaded 150 KB
trying URL 'http://rspm/default/__linux__/focal/latest/src/contrib/GGally_2.2.1.tar.gz'
Content type 'application/x-gzip' length 1985679 bytes (1.9 MB)
==================================================
downloaded 1.9 MB
* installing *binary* package ‘proxy’ ...
* DONE (proxy)
* installing *binary* package ‘DEoptimR’ ...
* DONE (DEoptimR)
* installing *binary* package ‘htmlwidgets’ ...
* DONE (htmlwidgets)
* installing *binary* package ‘coda’ ...
* DONE (coda)
* installing *binary* package ‘patchwork’ ...
* DONE (patchwork)
* installing *binary* package ‘som’ ...
* DONE (som)
* installing *binary* package ‘lars’ ...
* DONE (lars)
* installing *binary* package ‘pls’ ...
* DONE (pls)
* installing *binary* package ‘mclust’ ...
* DONE (mclust)
* installing *binary* package ‘sp’ ...
* DONE (sp)
* installing *binary* package ‘tweenr’ ...
* DONE (tweenr)
* installing *binary* package ‘polyclip’ ...
* DONE (polyclip)
* installing *binary* package ‘gridExtra’ ...
* DONE (gridExtra)
* installing *binary* package ‘Formula’ ...
* DONE (Formula)
* installing *binary* package ‘rJava’ ...
* DONE (rJava)
* installing *binary* package ‘brew’ ...
* DONE (brew)
* installing *binary* package ‘hunspell’ ...
* DONE (hunspell)
* installing *binary* package ‘estimability’ ...
* DONE (estimability)
* installing *binary* package ‘mvtnorm’ ...
* DONE (mvtnorm)
* installing *binary* package ‘igraph’ ...
* DONE (igraph)
* installing *binary* package ‘labelled’ ...
* DONE (labelled)
* installing *binary* package ‘maps’ ...
* DONE (maps)
* installing *binary* package ‘crosstalk’ ...
* DONE (crosstalk)
* installing *binary* package ‘vdiffr’ ...
* DONE (vdiffr)
* installing *binary* package ‘e1071’ ...
* DONE (e1071)
* installing *binary* package ‘pcaPP’ ...
* DONE (pcaPP)
* installing *binary* package ‘robustbase’ ...
* DONE (robustbase)
* installing *binary* package ‘htmlTable’ ...
* DONE (htmlTable)
* installing *binary* package ‘viridis’ ...
* DONE (viridis)
* installing *binary* package ‘statnet.common’ ...
* DONE (statnet.common)
* installing *binary* package ‘broom.helpers’ ...
* DONE (broom.helpers)
* installing *binary* package ‘geosphere’ ...
* DONE (geosphere)
* installing *binary* package ‘ggforce’ ...
* DONE (ggforce)
* installing *binary* package ‘mapproj’ ...
* DONE (mapproj)
* installing *binary* package ‘scagnostics’ ...
* DONE (scagnostics)
* installing *binary* package ‘roxygen2’ ...
* DONE (roxygen2)
* installing *binary* package ‘spelling’ ...
* DONE (spelling)
* installing *binary* package ‘emmeans’ ...
* DONE (emmeans)
* installing *binary* package ‘ggstats’ ...
* DONE (ggstats)
* installing *binary* package ‘chemometrics’ ...
* DONE (chemometrics)
* installing *binary* package ‘Hmisc’ ...
* DONE (Hmisc)
* installing *binary* package ‘network’ ...
* DONE (network)
* installing *binary* package ‘intergraph’ ...
* DONE (intergraph)
* installing *binary* package ‘sna’ ...
* DONE (sna)
* installing *binary* package ‘GGally’ ...
* DONE (GGally)
The downloaded source packages are in
‘/tmp/RtmpwBrd26/downloaded_packages’
Loading required package: GGally
Registered S3 method overwritten by 'GGally':
method from
+.gg ggplot2
Use the read_sav() function from the Haven package to import an SPSS file into R.
Documentation can be viewed here
dataset <- read_sav("https://osf.io/98mt6/download")
Use the View() function to look at your dataset like you would in SPSS or Excel
Documentation can be viewed here
#View(dataset)
This is useful if you used haven to import an SPSS file created by Qualtrics
Documentation can be viewed here
dataset %>%
map(~ attr(., "label"))
$StartDate
[1] "Start Date"
$EndDate
[1] "End Date"
$Status
[1] "Response Type"
$Progress
[1] "Progress"
$Duration__in_seconds_
[1] "Duration (in seconds)"
$Finished
[1] "Finished"
$RecordedDate
[1] "Recorded Date"
$ResponseId
[1] "Response ID"
$RecipientLastName
[1] "Recipient Last Name"
$RecipientFirstName
[1] "Recipient First Name"
$RecipientEmail
[1] "Recipient Email"
$ExternalReference
[1] "External Data Reference"
$LocationLatitude
[1] "Location Latitude"
$LocationLongitude
[1] "Location Longitude"
$DistributionChannel
[1] "Distribution Channel"
$UserLanguage
[1] "User Language"
$CoinFlip
[1] "Flip a coin. Is it heads or tails?"
$FFM_1
[1] "I see Myself as Someone Who..... - Is talkative"
$FFM_2
[1] "I see Myself as Someone Who..... - Tends to find fault with others"
$FFM_3
[1] "I see Myself as Someone Who..... - Does a thorough job"
$FFM_4
[1] "I see Myself as Someone Who..... - Is depressed, blue"
$FFM_5
[1] "I see Myself as Someone Who..... - Is original, comes up with new ideas"
$FFM_6
[1] "I see Myself as Someone Who..... - Is reserved"
$FFM_7
[1] "I see Myself as Someone Who..... - Is helpful and unselfish with others"
$FFM_8
[1] "I see Myself as Someone Who..... - Can be somewhat careless"
$FFM_9
[1] "I see Myself as Someone Who..... - Is relaxed, handles stress well"
$FFM_10
[1] "I see Myself as Someone Who..... - Is curious about many different things"
$FFM_11
[1] "I see Myself as Someone Who..... - Is full of energy"
$FFM_12
[1] "I see Myself as Someone Who..... - Starts quarrels with others"
$FFM_13
[1] "I see Myself as Someone Who..... - Is a reliable worker"
$FFM_14
[1] "I see Myself as Someone Who..... - Can be tense"
$FFM_15
[1] "I see Myself as Someone Who..... - Is ingenious, a deep thinker"
$FFM_16
[1] "I see Myself as Someone Who..... - Generates a lot of enthusiasm"
$FFM_17
[1] "I see Myself as Someone Who..... - Has a forgiving nature"
$FFM_18
[1] "I see Myself as Someone Who..... - Tends to be disorganized"
$FFM_19
[1] "I see Myself as Someone Who..... - Worries a lot"
$FFM_20
[1] "I see Myself as Someone Who..... - Has an active imagination"
$FFM_21
[1] "I see Myself as Someone Who..... - Tends to be quiet"
$FFM_22
[1] "I see Myself as Someone Who..... - Is generally trusting"
$FFM_23
[1] "I see Myself as Someone Who..... - Tends to be lazy"
$FFM_24
[1] "I see Myself as Someone Who..... - Is emotionally stable, not easily upset"
$FFM_25
[1] "I see Myself as Someone Who..... - Is inventive"
$FFM_26
[1] "I see Myself as Someone Who..... - Has an assertive personality"
$FFM_27
[1] "I see Myself as Someone Who..... - Can be cold and aloof"
$FFM_28
[1] "I see Myself as Someone Who..... - Perseveres until the task is finished"
$FFM_29
[1] "I see Myself as Someone Who..... - Can be moody"
$FFM_30
[1] "I see Myself as Someone Who..... - Values artistic, aesthetic experiences"
$FFM_31
[1] "I see Myself as Someone Who..... - Is sometimes shy, inhibited"
$FFM_32
[1] "I see Myself as Someone Who..... - Is considerate and kind to almost everyone"
$FFM_33
[1] "I see Myself as Someone Who..... - Does things efficiently"
$FFM_34
[1] "I see Myself as Someone Who..... - Remains calm in tense situations"
$FFM_35
[1] "I see Myself as Someone Who..... - Prefers work that is routine"
$FFM_36
[1] "I see Myself as Someone Who..... - Is outgoing, sociable"
$FFM_37
[1] "I see Myself as Someone Who..... - Is sometimes rude to others"
$FFM_38
[1] "I see Myself as Someone Who..... - Makes plans and follows through with them"
$FFM_39
[1] "I see Myself as Someone Who..... - Gets nervous easily"
$FFM_40
[1] "I see Myself as Someone Who..... - Likes to reflect, play with ideas"
$FFM_41
[1] "I see Myself as Someone Who..... - Has few artistic interests"
$FFM_42
[1] "I see Myself as Someone Who..... - Likes to cooperate with others"
$FFM_43
[1] "I see Myself as Someone Who..... - Is easily distracted"
$FFM_44
[1] "I see Myself as Someone Who..... - Is sophisticated in art, music, or literature"
$Potter1
[1] "Dawn or Dusk"
$Potter2
[1] "Forest or River?"
$Potter3
[1] "Moon or Stars?"
$Potter4
[1] "Black or White?"
$Potter5
[1] "Heads or Tails?"
$Potter6
[1] "Left or Right?"
$Potter7
[1] "Four boxes are placed before you. Which would you try and open?"
$Potter8
[1] "You and two friends need to cross a bridge guarded by a river troll who insists on fighting one of you before he will let all of you pass. Do you:"
$Potter9
[1] "Once every century, the Flutterby bush produces flowers that adapt their scent to attract the unwary. If it lured you, it would smell of:"
$Potter10
[1] "One of your housemates has cheated in a Hogwarts exam by using a Self-Spelling Quill. Now he has come top of the class in Charms, beating you into second place. Professor Flitwick is suspicious of what happened. He draws you to one side after his lesson and asks you whether or not your classmate used a forbidden quill. What do you do?"
$Potter11
[1] "Which of the following do you find most difficult to deal with?"
$Potter12
[1] "You enter an enchanted garden. What would you be most curious to examine first?"
$Potter13
[1] "Four goblets are placed before you. Which would you choose to drink?"
$Potter14
[1] "What kind of instrument most pleases your ear?"
$Potter15
[1] "Which of the following would you most hate people to call you?"
$Potter16
[1] "After you have died, what would you most like people to do when they hear your name?"
$Potter17
[1] "How would you like to be known to history?"
$Potter18
[1] "A Muggle confronts you and says that they are sure you are a witch or wizard. Do you:"
$Potter19
[1] "Which nightmare would frighten you the most?"
$Potter20
[1] "If you were attending Hogwarts, which pet would you choose to take with you?"
$Potter21
[1] "Given the choice, would you rather invent a potion that would guarantee you:"
$Potter22
[1] "If you could have any power, which would you choose?"
$Potter23
[1] "Which road tempts you most?"
$Potter24
[1] "Late at night, walking alone down the street, you hear a peculiar cry that you believe to have a magical source. Do you:"
$Potter25
[1] "What are you most looking forward to learning at Hogwarts?"
$Potter26
[1] "Which of the following would you most like to study?"
$Potter27
[1] "A troll has gone berserk in the Headmaster’s study at Hogwarts. It is about to smash, crush and tear several irreplaceable items and treasures. In which order would you rescue these objects from the troll’s club, if you could?"
$Potter28
[1] "Which would you rather be:"
$extraversionTidy
NULL
$FlipHeadsDummy
NULL
$CoinFlipFactor
NULL
Use the Select() function to de-select a column.
Put ‘-’ before the column name to remove a column (you can list more than one column).
Just type the column name to keep only that column (you can list more than one column).
Documentation can be viewed here
dataset %>%
select(-IPAddress) -> dataset
Use the slice() funciton to remove rows.
Put the range of rows you’d like to remove with minus signs in front.
Documentation can be viewed here
dataset %>%
slice(-1:-3) -> dataset
Use the tidyverse, mutate, and case_when to recode variables Documentation can be viewed here
dataset %>%
mutate(CoinFlipFactor = case_when(CoinFlip==1 ~ "Heads",
CoinFlip==2 ~ "Tails")) -> dataset
dataset %>%
mutate(FlipHeadsDummy = case_when(CoinFlip==1 ~ 1,
CoinFlip==2 ~ 0)) -> dataset
Documentation can be viewed here
#First select the variables you'd like to summarize
dataset %>%
select (CoinFlip, FFM_5, Potter3) -> exampleDF
#Then print them with this command
print(dfSummary(exampleDF, graph.magnif = .75), method = 'render')
Warning: unable to open connection to X11 display ''
| No | Variable | Label | Stats / Values | Freqs (% of Valid) | Graph | Valid | Missing | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | CoinFlip [haven_labelled, vctrs_vctr, double] | Flip a coin. Is it heads or tails? |
|
|
118 (96.7%) | 4 (3.3%) | |||||||||||||||||||||||||||||
| 2 | FFM_5 [haven_labelled, vctrs_vctr, double] | I see Myself as Someone Who..... - Is original, comes up with new ideas |
|
|
97 (79.5%) | 25 (20.5%) | |||||||||||||||||||||||||||||
| 3 | Potter3 [haven_labelled, vctrs_vctr, double] | Moon or Stars? |
|
|
101 (82.8%) | 21 (17.2%) |
Generated by summarytools 1.0.1 (R version 4.3.3)
2024-03-26
Documentation can be viewed here
#First select the variables you'd like to summarize
dataset %>%
select (CoinFlip, FFM_5, Potter3) %>%
Documentation can be viewed here
#create dataframe with only relevant variables to work with
Extraversion <- data.frame (dataset$FFM_1, dataset$FFM_6, dataset$FFM_11, dataset$FFM_16, dataset$FFM_21, dataset$FFM_26, dataset$FFM_31, dataset$FFM_36)
#create list of 'keys'. The numbers just refer to the order of the question in the data.frame() you just made. The most important thing is to mark the questions that should be reversed scored with a '-'.
#score the scale
Extraversion.scales <- scoreItems (Extraversion.keys, Extraversion)
#save the scores
Extraversion.scores <- Extraversion.scales$scores
#save the scores back in 'dataset'
dataset$Extraversion <- Extraversion.scores[,]
#print the cronbach alpha
Extraversion.scales$alpha
#create dataframe with only relevant variables to work with
Agreeableness <- data.frame (dataset$FFM_2, dataset$FFM_7, dataset$FFM_12, dataset$FFM_17, dataset$FFM_22, dataset$FFM_27, dataset$FFM_32, dataset$FFM_37, dataset$FFM_42)
Agreeableness.scales <- scoreItems (Agreeableness.keys, Agreeableness)
Agreeableness.scores <- Agreeableness.scales$scores
dataset$Agreeableness <- Agreeableness.scores[,]
Agreeableness.scales$alpha
#create dataframe with only relevant variables to work with
Conscientiousness <- data.frame (dataset$FFM_3, dataset$FFM_8, dataset$FFM_13, dataset$FFM_18, dataset$FFM_23, dataset$FFM_28, dataset$FFM_33, dataset$FFM_38, dataset$FFM_43)
my.scales <- scoreItems (my.keys, Conscientiousness)
my.scores <- my.scales$scores
dataset$Conscientiousness <- my.scores[,]
my.scales$alpha
#create dataframe with only relevant variables to work with
Neuroticism <- data.frame (dataset$FFM_4, dataset$FFM_9, dataset$FFM_14, dataset$FFM_19, dataset$FFM_24, dataset$FFM_29, dataset$FFM_34, dataset$FFM_39)
my.scales <- scoreItems (my.keys, Neuroticism)
my.scores <- my.scales$scores
dataset$Neuroticism <- my.scores[,]
my.scales$alpha
#create dataframe with only relevant variables to work with
Openness <- data.frame (dataset$FFM_5, dataset$FFM_10, dataset$FFM_15, dataset$FFM_20, dataset$FFM_25, dataset$FFM_30, dataset$FFM_35, dataset$FFM_40, dataset$FFM_41, dataset$FFM_44)
my.scales <- scoreItems (my.keys, Openness)
my.scores <- my.scales$scores
dataset$Openness <- my.scores[,]
my.scales$alpha
Documentation can be viewed here
dataset %>%
select(Openness, Conscientiousness, Extraversion, Agreeableness, Neuroticism) %>%
correlate() %>%
shave() %>%
Documentation can be viewed here
dataset %>%
select(Conscientiousness, Extraversion, Agreeableness, Neuroticism) -> Big5df
corr.test(x = Big5df,
y = NULL,
use = "pairwise",
method = "pearson",
adjust = "holm",
alpha = .05,
ci = TRUE)
Documentation can be viewed here
dataset %>%
select(Openness, Conscientiousness, Extraversion, Agreeableness, Neuroticism) %>%
ggpairs()
Documentation can be viewed here
dataset %>%
with(t.test(Agreeableness ~ CoinFlipFactor))
Error in model.frame.default(formula = Agreeableness ~ CoinFlipFactor) :
invalid type (list) for variable 'Agreeableness'
dataset %>%
with(t.test(Agreeableness, Neuroticism, paired = TRUE))
Error in `[.data.frame`(y, yok) : undefined columns selected