Coding, Database, R Language

The power of R scripting – don't be afraid of code

R is a programming language for statistical analyses and data operations that may seem daunting at first, but is really compelling and elegant once you get used to it. And it can make your life so much easier. Here are the impressions of a newbie.

06 MIN

R is not for me, right?

I always thought R was for statistics nerds only, not to be used for analyses in “normal” UX research. But then I was forced to use it in a recent project and its power and elegance impressed me. How did I end up using R? We created a dashboard for one of our clients with various UX KPI across a range of products. The dashboard was created in Microsoft PowerBI, which provides great data visualization tools and allows the user to create custom analyses with a few clicks. But it does not do statistics well, relying on R integration instead.

 

Why R? Some examples

A couple of examples that make R such a pleasure to use:

  • Typical procedures are super simple: calculating a KPI from multiple columns per participant is a one-liner because R treats data as vectors new_value <- rowMeans(…)
  • Running different statistical tests depending on the data’s properties (e.g. sample size, distribution) is very easy: write your own function if (data property = X) return (statistical test Y) and use it throughout your code.
  • Working with larger data sets is very convenient, because you can use subsets of data on the fly with the “subset” function.
  • Data transformation is quick and powerful: Convert data from long to wide, differentiating separate measurements, with a function called “dcast”.

All of this is also possible in SPSS, but it would require a lot of clicking through dialogues and assistants. For somebody like me who isn’t much of a SPSS syntax pro, I was surprised how easy it was in R.

 

The power of the community

But of course, learning R meant a lot of questions – it’s not something you learn in an afternoon. However, R has such a large and helpful community that there’s almost always an answer out there. There are numerous pages that tell you about the basics of using R, and whenever I had a more specific problem, I would almost always find the solution in one of the many active online communities. Learning R might be a bit difficult, but you’re definitely not alone.

 

Packages for every occasion

The solutions you find online will often use so-called packages through which you can expand R’s features. And R being open source means there are packages for almost any occasion, created and verified by the community.

 

 

 

R in a nutshell

R is a programming language that is free to use under the GNU licence. It comes with a broad set of statistical functions and can be expanded almost infinitely with the help of packages provided by the community. Development environments such as RStudio make life a lot easier.

My suggestion: Get RStudio, get real data to work with (to prevent playing around aimlessly), check out the tutorial pages and: have some patience!

Here you can find RStudio and tutorials:

 

Is R for me?

Plus

  • R code is quite similar to other programming languages, so if you have dabbled a bit in coding before it might be easier to understand than SPSS syntax (was for me).
  • Once you get the hang of it, analyses are super quickly done and the code can be optimized and reused later.
  • Graphical output is said to be more powerful and customizable than SPSS (not yet tested).
  • There’s a certain joy in doing complex data operations and statistical analyses with a couple of lines of elegant code – at least for me.
  • It’s free!

Minus

  • No graphical user interface, harder to learn because you need to code

 

Final words

I probably wouldn’t have started using R had I not been “forced” to by PowerBI. But in retrospect, I’m glad I did! If you own SPSS, you won’t be using R for a quick mean or statistical test. However, if you know you’re going to be doing more extensive data transpositions and analyses, and potentially do them repeatedly, R might be worth looking into. Especially if SPSS seems to make what you are trying to do unnecessarily complex. I will definitely use R for future projects.

Author

Simon Harder

Simon has been a UX professional since 2011, after completing his thesis in psychology on the development of the UX Score measurement tool. Since then, he has worked for SirValUse and GfK until he co-founded uintent in 2018. As a UX consultant, he conducted many international projects, including several visits to China for field phases. He also managed several summative studies to quantitatively measure the User Experience of HMIs. Among those were a number of automotive studies, e. g. with task-based interviews or occlusion testing. At uintent, Simon focuses on UX research, qual and quant.

Go back