WB-ILIAS | Weiterbildung und offene Bildungsressourcen

R

Interface

After the installation, you should be able to run R. The interface should look similar to the following picture:

The opened window is the R-console. It works similar to a command line: commands can be typed in and will be carried out immediately after confirmation (pressing RETURN key on the keyboard).

In the simplest form, the R-console can work as a simple calculator.
Try it out: type in 5 + 2 in the console and confirm the command. Then type in 5 * 2 and confirm again. Then try 6/3 + 3.
As you can see, R performs the calculation for you and returns the result. The [1] at the beginning of the returned value stands for the first (and in these examples only) item of the result.

What if you carry out operations frequently and don’t want to type them every time? Or what if you need to write a complex code that would be hard to navigate in the console? For these purposes, you can write and save a script that you can later load and execute. By going to File > New script another window opens. There, you can write the code just like in the console. Pressing RETURN, however, will not execute it, but create a new line. In order to execute a line in the script, you can position your cursor on it and press the button Carry out line or selection in the ribbon above the console (on Windows systems, this corresponds to Ctrl + R). If you select multiple lines before pressing this button, they will all be carried out from top to bottom.

To save the script, go to File > Save as… This will save the script itself, not your results.

qtitle


Bisher wurde noch kein Kommentar abgegeben.