Basic R Programming Examples With Output

Basic R Programming Examples With Output

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

R Programming:

Once you have R environment setup, then it’s easy to start your R command prompt by just typing the following command at your command prompt-

$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

When we run the above program, it produces the following output.

Output:

[1] “Hello World!”

Here first statement defines a string variable firstString, where we assign a string “Hello World!” and then next statement print () is being used to print the value stored in variable firstString.

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)

#If you have to print more than one value then use the function paste () or get ().

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

Output:

[1] “Welcome to my first program”

If there are more than one item, we can use the paste () and cat () function to concatenate the string together.

Here,Some 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 Languge
13. Find factors using R Programming Language
14. Write a R Program to Find GCD
15.Write a R Program to Find LCM

No Comments

Post a Reply