Load Packages
haven
# 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)
}
## Loading required package: haven
tidyverse
if (!require(tidyverse)){
install.packages("tidyverse", dependencies = TRUE)
library(tidyverse)
}
## Loading required package: tidyverse
## ── 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
Import Data
dataset <- read_sav("Harry Potter Data.sav")
Codebook
#First select the variables you'd like to summarize
dataset %>%
select (CoinFlip, FFM_2, Potter2) -> exampleDF
#Then print them with this command
print(dfSummary(exampleDF, graph.magnif = .75), method = 'render')
## Warning in png(png_loc <- tempfile(fileext = ".png"), width = 150 *
## graph.magnif, : unable to open connection to X11 display ''
## Warning in png(png_loc <- tempfile(fileext = ".png"), width = 150 *
## graph.magnif, : unable to open connection to X11 display ''
## Warning in png(png_loc <- tempfile(fileext = ".png"), width = 150 *
## graph.magnif, : unable to open connection to X11 display ''
Data Frame Summary
exampleDF
Dimensions: 122 x 3
Duplicates: 96
| 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_2
[haven_labelled, vctrs_vctr, double] |
I see Myself as Someone Who..... -
Tends to find fault with others |
| Mean (sd) : 2.6 (1.1) | | min ≤ med ≤ max: | | 1 ≤ 2 ≤ 5 | | IQR (CV) : 2 (0.4) |
|
| 1 | : | 16 | ( | 16.3% | ) | | 2 | : | 35 | ( | 35.7% | ) | | 3 | : | 19 | ( | 19.4% | ) | | 4 | : | 24 | ( | 24.5% | ) | | 5 | : | 4 | ( | 4.1% | ) |
|
 |
98
(80.3%) |
24
(19.7%) |
| 3 |
Potter2
[haven_labelled, vctrs_vctr, double] |
Forest or River? |
|
|
 |
101
(82.8%) |
21
(17.2%) |
Generated by summarytools 1.0.1 (R version 4.3.1)
2023-07-13