How to write first code in R Programming – Explained practically

Writing the first code in R or using R is one of the first and foremost basic skills a user should attain. To write the first code using the R programming language, you can create a simple script that prints a string to the console.

Let’s have the example practically below:

myString <- “Hello, World!”

print (myString)

Study the above code as seen and entered. To run the code, you will need to save it with an ‘R’ extension and later execute it using the ‘Rscript’ command or syntax in your terminal or command prompt.

$ Rscript test.R

The output, or result, is expected to be:

[1] “Hello, World!”

Additionally, you can also add a comment feature to your entire code to explain what it does. Meanwhile, in R, cmments are supposed to start with the ‘#’ symbol and continue to the end of the entire line.

Consider the example below:

This is a comment

myString <- “Hello, World!” # This assigns a string to the variable “myString.”

print (myString) # This prints the value of “myString” to the console

 

Congratulations! I am very certain this helps you get started with R programming! Let me know if you have more or any other questions.

Related posts:

About Author


Discover more from SURFCLOUD TECHNOLOGY

Subscribe to get the latest posts sent to your email.

Leave a Reply

Your email address will not be published. Required fields are marked *

Discover more from SURFCLOUD TECHNOLOGY

Subscribe now to keep reading and get access to the full archive.

Continue reading