filmov
tv
R Tutorial: Writing Efficient R Code | Intro

Показать описание
---
R has the unfortunate reputation for being slow. While it is certainly true that in a competition of raw speed with a language like C, R would come in a distant second. This is an unfair comparison to make. Instead, the total programming time is made up of three components. Thinking, coding and running.
In many statistical analyses, we want to try multiple methods. Therefore, we want the thinking and coding part optimised. This is R's strength, By the time we've loaded data into R, created a scatter plot and fitted a regression line, our friendly C programmer would have just launched their code editor and would be checking stackoverflow for how to read in a CSV file.
We use R because it is good with statistics. However with the advent of big data and complex statistical algorithms, we may have to optimise our code.
Before we jump straight in at the deep end, we should remember what Donald Knuth said
premature optimization is the root of all evil
That is, only optimize when necessary. If you've never heard of Donald Knuth. He's a Stanford computing science professor who created the typesetting program TeX and invented several random number generation algorithms.
Before we finish this introduction, there is one simple optimization we should ensure we use. Keep R up-to-date. New versions of R rarely break code; in fact I have R code from turn of the century that still works! New versions of R often provide speed boosts, such as improved handling of data frames, so your code just goes a little bit faster.
#DataCamp #RTutorial #Writing #Efficient #RCode