Learn R Programming

Data Science for Psychologists (ds4psy)

Welcome to the R package ds4psy — a software companion to the books and courses Data Science for Psychologists and Introduction to Data Science.

This R package provides datasets and functions used in the ds4psy and i2ds textbooks and corresponding course curricula. These books and courses introduce the principles and methods of data science for students of psychology and other biological or social sciences.

Installation

The current release of ds4psy is available from CRAN at https://CRAN.R-project.org/package=ds4psy:

install.packages('ds4psy')  # install ds4psy from CRAN client
library('ds4psy')           # load to use the package

The current development version of ds4psy (v1.4.0) can be installed from its GitHub repository at https://github.com/hneth/ds4psy/:

# install.packages('devtools')  # (if not installed yet)
devtools::install_github('hneth/ds4psy')
library('ds4psy')  # load to use the package

Textbooks

The R package ds4psy is used by two textbooks that are freely available online. Current versions of the ds4psy book and i2ds book are available at https://hneth-ds4psy.share.connect.posit.cloud/ and https://hneth-i2ds.share.connect.posit.cloud/, respectively.

Change of hosting service and URLs

Both textbooks were originally hosted at https://bookdown.org (up to 2026-01-15). Static versions are still available at https://bookdown.org/hneth/ds4psy/ and https://bookdown.org/hneth/i2ds/, respectively, but these are no longer updated.

Future versions will be hosted at https://connect.posit.cloud/hneth/. Hence, visit https://hneth-ds4psy.share.connect.posit.cloud/ and https://hneth-i2ds.share.connect.posit.cloud/ for the most recent versions.

Course Coordinates

Overview

This R package and the corresponding books and courses provide an introduction to data science that is tailored to the needs of students in psychology, but is also suitable for students of the humanities and other biological or social sciences. This audience typically has some knowledge of statistics, but rarely an idea how data is prepared and shaped to allow for statistical testing. By using various data types and working with many examples, we teach tools for transforming, summarizing, and visualizing data. By keeping our eyes open for the perils of misleading representations, the book fosters fundamental skills of data literacy and cultivates reproducible research practices that enable and precede any practical use of statistics.

Audiences

Students of psychology and other social sciences are trained to analyze data. But the data they learn to work with (e.g., in courses on statistics and empirical research methods) is typically provided to them and structured in a (rectangular or “tidy”) format that presupposes many steps of data processing regarding the aggregation and spatial layout of variables. When beginning to collect their own data, students inevitably struggle with these pre-processing steps which — even for experienced data scientists — tend to require more time and effort than choosing and conducting statistical tests.

This course develops the foundations of data analysis that allow students to collect data from real-world sources and transform and shape such data to answer scientific and practical questions. Although there are many good introductions to data science (e.g., Grolemund & Wickham, 2017) they typically do not take into account the special needs — and often anxieties and reservations — of psychology students. As social scientists are not computer scientists, we introduce new concepts and commands without assuming a mathematical or computational background. Adopting a task-oriented perspective, we begin with a specific problem and then solve it with some combination of data collection, manipulation, and visualization.

Goals

Our main goal is to develop a set of useful skills in analyzing real-world data and conducting reproducible research. Upon completing this course, you will be able to use R to read, transform, analyze, and visualize data of various types. Many interactive exercises allow students to continuously check their understanding, practice their skills, and monitor their progress.

Requirements

The courses using this package assume some basic familiarity with statistics and the R programming language, but enthusiastic programming novices are welcome.

Resources

This package and the corresponding books are still being developed and are updated as new materials become available.

References

Course materials

These books and courses were originally based on the classic textbook:

  • Wickham, H., & Grolemund, G. (2017). R for data science: Import, tidy, transform, visualize, and model data. Sebastopol, Canada: O’Reilly Media, Inc. (available online at https://r4ds.had.co.nz/)

but provide more base R and less tidyverse content.

Software

Please install the following open-source programs on your computer:

# Tidyverse packages: 
install.packages('tidyverse')

# Course packages: 
install.packages('ds4psy')  # datasets and functions
install.packages('unikn')   # color palettes and functions

Other resources

R manuals and books

Software tools

  • See also the link collections at the end of each chapter of the ds4psy book.

About

If you find these materials useful, or want to adopt or alter them for your purposes, please let me know.

Citation

To cite ds4psy in derivations and publications, please use:

A BibTeX entry for LaTeX users is:

@Manual{,
  title = {ds4psy: Data Science for Psychologists},
  author = {Hansjörg Neth},
  year = {2026},
  organization = {Social Psychology and Decision Sciences, University of Konstanz},
  address = {Konstanz, Germany},
  note = {R package (version 1.4.0, November 4, 2026); Textbook at <https://hneth-ds4psy.share.connect.posit.cloud/>.},
  url = {https://CRAN.R-project.org/package=ds4psy},
  doi = {10.5281/zenodo.7229812},
}

The stable URL of the ds4psy R package is https://CRAN.R-project.org/package=ds4psy.

License

Data science for psychologists (ds4psy) by Hansjörg Neth is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.


[File README.md updated on 2026-11-04.]

Copy Link

Version

Install

install.packages('ds4psy')

Monthly Downloads

675

Version

1.4.0

License

CC BY-SA 4.0

Issues

Pull Requests

Stars

Forks

Maintainer

Hansjoerg Neth

Last Published

November 4th, 2026

Functions in ds4psy (1.4.0)

chars_to_text

Combine character inputs x into a single string of text
base2dec

Convert a string of numeral digits from some base into decimal notation
coin

Flip a fair coin (with 2 sides "H" and "T") n times
data_t1_tab

Data import data_t1_tab.
cur_time

Get current time (in hh:mm or hh:mm:ss format)
data_1

Data import data_1.
data_2

Data import data_2.
exp_num_dt

Data from an experiment with numeracy and date-time variables
data_t1_de

Data import data_t1_de.
ds4psy.guide

Open the ds4psy package's user guide.
count_words

Count the frequency of words in a character string/text
diff_times

Get the difference between two times (in human units)
exp_wide

Data exp_wide.
change_tz

Change time zone (without changing the represented time)
data_t3

Data table data_t3.
falsePosPsy_all

Data: False Positive Psychology
data_t1

Data table data_t1.
dt_10

Data from 10 Danish people
dec2base

Convert an integer from decimal notation into a string of numeric digits in some base
data_t2

Data table data_t2.
days_in_month

How many days are in a month (of given date)?
is_leap_year

Is some year a so-called leap year?
dice_2

Throw a questionable dice (with a given number of sides) n times
map_text_coord

map_text_coord maps the characters of a text string into a table (with x/y-coordinates).
data_t4

Data table data_t4.
map_text_regex

Map text to character table (allowing for matching patterns)
dice

Throw a fair dice (with a given number of sides) n times
is_vect

Test for a vector (i.e., atomic vector or list).
num_as_ordinal

Convert a number into an ordinal character sequence
diff_dates

Get the difference between two dates (in human units)
diff_tz

Get the time zone difference between two times.
get_set

Get a set of x-y coordinates (from Anscombe's Quartet)
num_equal

Test two numeric vectors for pairwise (near) equality
plot_fun

An example function to plot some plot
invert_rules

invert_rules() inverts a set of encoding rules
plot_n

Plot n tiles
make_grid

Generate a grid of x-y coordinates.
fame

Data: fame
flowery

Data: Flowery phrases
i2ds_survey

Data from the i2ds online survey
map_text_chars

map_text_chars maps the characters of a text string into a table (with x/y coordinates).
pal_n_sq

Get n-by-n dedicated colors of a color palette
pi_100k

Data: 100k digits of pi.
is_wholenumber

Test for whole numbers (i.e., integers)
read_ascii

Parse text (from file or user input) into string(s) of text
is_equal

Test two vectors for pairwise (near) equality
plot_text

Plot text characters (from file or user input)
outliers

Outlier data.
plot_tiles

Plot n-by-n tiles.
sample_char

Draw a sample of n random characters (from given characters)
tb

Data table tb.
text_to_chars

Split string(s) of text x into its characters
fruits

Data: Names of fruits
pal_ds4psy

ds4psy default color palette.
l33t_rul35

Rules for translating text into leet/l33t slang
transl33t

Translate text into leet slang
t4

Data: t4
t3

Data: t3
theme_empty

A basic and flexible plot theme (using ggplot2)
plot_charmap

Plot a character map as a tile plot with text labels
plot_chars

Plot text characters (from file or user input) and match patterns
t_1

Data: t_1
sample_date

Draw a sample of n random dates (from a given range).
t_2

Data: t_2
sample_time

Draw a sample of n random times (from a given range).
table6

Data: table6
text_to_sentences

Split strings of text x into sentences
text_to_words

Split string(s) of text x into words
table7

Data: table7
metachar

metachar provides metacharacters (as a character vector)
zodiac

Get the astrological sign / zodiac symbol for date(s)
words_to_text

Paste or collapse words x into a text
posPsy_AHI_CESD

Positive Psychology: AHI CESD data
t_4

Data: t_4
theme_ds4psy

A basic and flexible plot theme
theme_clean

A clean alternative theme for ggplot2
what_week

What week is it?
posPsy_long

Positive Psychology: AHI CESD corrected data (in long format)
t_3

Data: t_3
what_month

What month is it?
what_date

What date is it?
num_as_char

Convert a number into a character sequence
plot_fn

A function to plot a plot
plot_circ_points

Plot objects (as points) arranged on a circle
posPsy_p_info

Positive Psychology: Participant data
what_year

What year is it?
what_time

What time is it?
posPsy_wide

Positive Psychology: All corrected data (in wide format)
table8

Data: table8
table9

Data table9.
what_wday

What day of the week is it?
base_digits

Base digits: Sequence of numeric symbols (as named vector)
capitalize

Capitalize initial characters in a string of text
cclass

cclass provides character classes (as a named vector)
Umlaut

Umlaut provides German Umlaut letters (as Unicode characters)
Trumpisms

Data: Trumpisms
change_time

Change time and time zone (without changing time display)
caseflip

Flip the case of characters in a string of text
cur_date

Get current date (in yyyy-mm-dd or dd-mm-yyyy format)
count_chars

Count the frequency of characters in a character string/text
count_chars_words

Count the frequency of characters and words in a character string/text
collapse_chars

Collapse character inputs x into a single character string
countries

Data: Names of countries
Bushisms

Data: Bushisms