Note that there are some explanatory texts on larger screens.

plurals
  1. USDavid Arenburg
    primarykey
    data
    text
    <p><a href="https://stackexchange.com/users/3597339"> <img src="https://stackexchange.com/users/flair/3597339.png" width="208" height="58" alt="profile for David Arenburg on Stack Exchange, a network of free, community-driven Q&amp;A sites" title="profile for David Arenburg on Stack Exchange, a network of free, community-driven Q&amp;A sites"> </a></p> <p>Some rules of thumb for new R users (According to myself):</p> <ol> <li><p>If you are working with <code>data.frame</code>s, forget there is a function called <code>apply</code>- whatever you do - <em>don't</em> use it. <em>Especially</em> with a margin of 1 (the only good usecase for this function is to operate over <code>matrix</code> columns- margin of 2).</p> <ul> <li>Some good alternatives: <code>?do.call</code>, <code>?pmax/pmin</code>, <code>?max.col</code>, <code>?rowSums/rowMeans/etc</code>, the awesome <code>matrixStats</code> packages (for matrices), <code>?rowsum</code> and many more</li> </ul></li> <li><p>For loops are not bad- don't listen to anyone who says otherwise. They are bad only in certain cases: </p> <ul> <li>If you use them to iterate over rows. </li> <li>If you are performing unvectorized/inefficient operation within each iteration </li> <li>If you are writing a loop for something that is already vectorized</li> </ul></li> <li><p>R is a vectorized language- meaning many operation were already written in C loops- so don't reinvent the wheel and write stuff in R loops if it was already written. With one exception- many of these functions work only with matrices. Hence, if you have a <code>data.frame</code> you should think twice if you want it to be converted it to a <code>matrix</code>(you may experience some unexpected consequences as a result), or can you avoid it.</p></li> <li><p><strong>Learn base R before you learn any fancy packages</strong> such as <code>dplyr</code>. It is a nice package and all, but it was designed for very specific things. Many many operations could be done much more efficiently using base R.</p></li> <li><p>Get familiar with R classes. Learn what is <code>factor</code> and how to use it. Know the difference between a <code>matrix</code> (a vector with a <code>dim</code> attribute) and a <code>data.frame</code> (a <code>list</code> of vectors). Learn how and when to work with <code>list</code>s or <code>array</code>s. Know the difference between <code>numeric</code> and <code>integer</code>. Read about floating points.</p></li> <li><p>Learn how and when yo use <code>lapply/sapply/vapply</code> - these could come useful many times</p></li> <li><p>You <em>must</em> learn some <code>?regex</code>. Must.</p></li> <li><p>Read <code>?S4groupGeneric</code> in order to discover which functions have <code>data.frame</code> methods (a very useful to know).</p></li> <li><p>Learn about <code>?methods</code></p></li> <li><p>Read <code>?strptime</code> very carefully (note the <code>Sys.setlocale("LC_TIME", "C")</code> part - could be a life saver).</p></li> <li><p>Read the damn docs. R has awesome documentation- please use it. You won't find anything even nearly as good in any other language (I know of). </p></li> </ol> <p>Like Barry Rowlingson once said: "<strong>This is all documented in TFM. Those who WTFM don't want to have to WTFM again on the mailing list. RTFM.</strong>"</p>
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload