R bloggers

Functional peace of mind

FavoriteLoadingAdd to favorites

I think what I enjoy the most about functional programming is the peace of mind that comes with it. With functional programming, there’s a lot of stuff you don’t need to think about. You can write functions that are general enough so that they solve a variety of problems. For example, imagine for a second that R does not have the sum() function anymore. If you want to compute the sum of, say, the first 100 integers, you could write a loop that would do that for you: numbers = 0 for (i in 1:100){ numbers = numbers + i } print(numbers) ## [1] 5050 The problem with this approach, is that you cannot reuse any of the code there, even if you put it inside a function. For instance, what if you want to merge 4 datasets together? You…
Original Post: Functional peace of mind