Improving your office Secret Santa with R (yes, really!)

If you’re joining your coworkers in the time-honored workplace tradition of Secret Santa this holiday season, look no further than this R function to improve efficiency and have a bit of fun too!

For those who may not be familiar with this particular holiday tradition, a group of people get together and everyone purchases a gift for one other person in the group. This is done anonymously, usually by picking names at random or choosing them from a list – hence the name: each person gets to play “Secret Santa” for someone else in the group.

In the post we’ve linked to above from the wonderful R-Bloggers website, the author has created an R function that takes a list of names as its input (the number of names in that list is read automatically from the object names so you don’t need to input that explicitly for the function to work). The function then randomly assigns each name in the group to another, thereby taking any guesswork or bias out of the process!

If you want to be the hero of your office Secret Santa this year, simply copy the function from the post we’ve linked to above (starting with the line: # make a function) into to R and run it – by default, the function object “secret_santa” gets saved by R, so you don’t need to run the source("secret-santa-function.R")  command provided by the post’s author unless you want to save this for later. Then, create your list of names for the  names object in R by replacing the author’s sample names with those from the people in your Secret Santa group. Don’t forget to wrap each name in quotes! Execute the names = c("your", "groups", "names", "go", "here", "separated", "by", "quotes") and n = length(names) commands, and finally call the function with secret_santa(n, names) to see the output of matched names for your Secret Santa!

If you’d like to learn more about BWF Insight, analytics using R statistical software, or if you just want to share your best Secret Santa stories, check out the BWF Insight website or contact us today!

Happy Holidays and Happy New Year from all of us at BWF Insight!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s