Basic User Functions in R

As I’ve been learning more about the data platform, I’ve been exposed to some R language code. This makes sense, as more comprehensive data analysis needs something other than SQL. Or at least, some people think that and it behooves me to better understand what they do with R. I’ve also had to build questions for SQLServerCentral, so I’ve spent time working through different R language items.

One of those items is the function. I first found this strange, but the more I think about it, the more I like this. Rather than some code that is a “create function double”, I actually assign a variable, which is really just some token in memory, to the function. I could do this as:

double <- function(x) { x * 2 }

This means the variable double contains a function, and I can call this as I would any function.

i <- double(4)

At this point, i would have the value 8.

Simple and easy, but powerful. This can get more complex, and I’ll experiment more in future posts.

About way0utwest

Editor, SQLServerCentral
This entry was posted in Blog and tagged , . Bookmark the permalink.

1 Response to Basic User Functions in R

  1. Cody L. Custis says:

    “This makes sense, as more comprehensive data analysis needs something other than SQL.”

    Linear modeling formed half of my graduate level statistics education. While there’s probably someone out there that wrote the routines to perform ordinary least squares regression in SQL, R’s lm() command is sufficient for the entirety of undergraduate level linear modeling; glm() covers most graduate level statistics (with the exception of specialized models).


Comments are closed.