Basic R Programming Examples With Output

Here, You can Learn Basic R Programming Examples with Output for Freshers

Top online courses in Programming Languages

R Programming:

After you set up R, opening the R program to type commands is simple. Just type “R” in your regular command prompt (like Command Prompt on Windows or Terminal on Mac), and press Enter. It’s like opening a special program for coding in R.

$R

This will launch R interpreter and you will get a prompt-Where you can start typing your first program as follows:

Basic “Hello World” program:
>firString <- “Hello World!”

#we can use the print () function

> print (firstString)

And next save the above code in file test.R and execute it at Linux command prompt as given below.evn if you are using windows or other different system, syntax will remain same. (The R Script is executed using Source command)

$ Rscript test.R

After running the code, you’ll see the message “Hello World!” on your screen.

Output:

[1] “Hello World!”

The code creates a variable named firstString and stores the message “Hello World!” inside it. After,  prints(print()) the message stored in the variable. In simpler terms, it creates a box named firstString, puts “Hello World!” in it.

Above Program (First example)

#Quotes can be suppresses in the output

> print (“Hello World!”, quote-FALSE)

Output:

 [1] Hello World!

The quotes are printed by default. To avoid this, we can pass the argument quote=FALSE

Above Program (Second example)

#Want to show multiple things? Use paste() or get() like a magic word combiner or revealer.

>print (paste (“Welcome”,”to”,”my”,“first”,”program”))

Output:

[1] “Welcome to my first program”

If you want to join things together? Use paste() or cat()

Top 15 Basic R Programming Examples

  1. Simple way:” Hello world program in R”
  2. Write a R Programs to Add, Sub, Mul, and Div 
  3. Write a R Program to Two vector Variables (Addition, Subtraction, Multiplication, Division, Mod, Coefficient)
  4. Find the maximum and minimum number in R Programming Language
  5. Find the position of minimum and maximum of value in R Programming Language
  6. Sort a vector in R Programming Language
  7. Multiplication Table in R Programming Language
  8. Fibonacci Sequence in R Programming Language
  9. Factorial of a number in R Programming Language
  10. Leap year or not in R Programming Language
  11. Check Armstrong number or Not in R Programming Language
  12. Find sum of natural numbers without/with formula using R Programming Language
  13. Find factors using R Programming Language
  14. Write a R Program to Find GCD
  15. Write a R Program to Find LCM 

 

Scroll to Top