Site icon R-bloggers

A technical interview question

[This article was first published on R – scottishsnow, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I was browsing #rstats on Twitter recently and came across this question:

Looking for R help! Does anyone have a line of code for what’s listed in column E here? I want to divide column A by B if column D is positive, and vice versa if D is negative. Hoping to use mutate and case_when. #RStats #Rhelp #dplyr pic.twitter.com/XAtePjTl4v

— Jamie Card (@jamietcard) August 25, 2021

Neat problem, I’ll take a quick look. So I answered the tweet. But the more I’ve dwelt on the question, and looked at the replies, the more I think this would make a great exercise in an interview. It’s a simple enough problem, but how someone chooses to answer it tells you a lot about the kind of colleague they would be.

Example responses ranged from a literal reading of the question, which used R to solve the problem in a spreadsheat way. To others who arrived at an answer, but discarded some steps not required by R. (these steps may have only been included to fully explain the question.

So, fancy having a go yourself? Here’s the sample data:

library(tidyverse)

tibble(A = c(100, 50, 100, 50),
            B = c(50, 100, 50, 100)) %>% 
  mutate(A_minus_B = A - B,
         sign = if_else(A_minus_B > 0,
                        "positive",
                        "negative"))

What would you do? What would you want to see from a candidate if you asked them this at an interview?

To leave a comment for the author, please follow the link and comment on their blog: R – scottishsnow.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.