Category Archives: Tips & Tricks

Formatting p-values: A curated list of R functions

Intro Reporting results of statistical analyses usually goes along with reporting p-values which indicate the probability under the null hypothesis of sampling a test statistic at least as extreme as that which was observed. R offers quite a lot of … Continue reading

Posted in Tips & Tricks | Tagged | Leave a comment

How to Vectorize a Function in R

Last year I came across the base R function Vectorize(). Vectorize() vectorizes the action of a non-vectorized function. Let's give an example. In one of my current research projects, I need to hash patient ids to fulfill the requirements of … Continue reading

Posted in Tips & Tricks | Tagged , , | Leave a comment

R Markdown Inline Code: Adding a Conjunction to Listings

In my last blog post, I wrote a couple of lines about EFFECT, a clinical trial I'm currently involved in. EFFECT is a cross-over trial with two wash-out and two study phases. After each of the four phases, the participating … Continue reading

Posted in Tips & Tricks | Tagged | Leave a comment

How to Check if a Date is Within a List of Intervals in R

Intro I'm currently involved in a research project called EFFECT. EFFECT is a multicentre, cluster-randomised, placebo-controlled cross-over trial evaluating antiseptic body wash of patients on intensive care units (ICU). The trial is to test whether daily antiseptic body wash reduces … Continue reading

Posted in Tips & Tricks | Tagged , , | Leave a comment

Drawing a Fish Curve using R and ggplot2

Intro Recently, I wondered whether there is a way to draw a fish shape using a mathematical function. Since I did not find a ready-made R function, I tried to write the function by myself. The equations, I've used for … Continue reading

Posted in Tips & Tricks, Visualizing Data | Tagged , | Leave a comment

How to order factors by level frequency and level name

Intro Quite frequently, factor variables are ordered by level frequency. However, factor levels having only a few observations are sometimes collapsed into one level usually named “others”. Since this level is usually not of particular interest, it may be a … Continue reading

Posted in Tips & Tricks, Visualizing Data | Tagged | 2 Comments

Postleitzahlen mit führender Null richtig formatieren

Intro Importiert man Postleitzahlen aus anderen Datenformaten (z.B. Excel, Access) in R, ist es nicht selten, dass Postleitzahlen programmintern tatsächlich auch als Zahlen abgespeichert werden. Wie ein Blick auf einen im Internet frei verfügbaren Datensatz zeigt, kann dies zu folgendem … Continue reading

Posted in Tips & Tricks | Tagged , | 2 Comments