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.

Original post (opens in new tab)
View comments in original post (opens in new tab)