Help!
How to get help when you are stuck? How to find and fix errors? That is the hardest part for beginners. You can start by checking the list of frequently used functions. And, there is always Google… Any question you may have as a beginner has been asked and answered before. Often on Stackoverlfow.
But at first it is hard to find the right search terms, and to distinguish between good answers, and “solutions” that just makes you dig deeper into the hole you are in. For that reason it is very important to be very careful with terminology, be a precise as possible. Do not call a vector a list, or a data.frame a matrix.
Learning how to create small examples that show how R (or any other computer language) works is perhaps the most important threshold to cross when learning R. As soon as you can create minimal, self-contained, reproducible examples you can ask effective questions. In most cases you will then also be able to answer them yourself! But if you cannot, surely someone on stackoverflow can.
Minimal means that when asking a question about how to do something in R, you simplify the code as much as possible, and focus on the very essence of the problem only. Your specific context is generally not relevant. So do not show a long script where all kinds of things happen that are OK. Rather, show the shortest possible script, using the smallest possible dataset, that gets you up to the point where you are stuck.
Reproducible means that anyone can run it in R and get the same
results. So you need to include set.seed
. Self-contained means that
it should not point to files you only have. You could make these
available, but why complicate things? Just create some data with code or
use a data set that comes with R (e.g. “cars”, “iris”, but there are
many). See the examples in the R help files for 1000s of ideas of how
you can do this.
For more discussion see this posting guide and this discussion