Here, You can Learn Basic R Programming Examples with Output for Freshers
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
- Simple way:” Hello world program in R”
- Write a R Programs to Add, Sub, Mul, and Div
- Write a R Program to Two vector Variables (Addition, Subtraction, Multiplication, Division, Mod, Coefficient)
- Find the maximum and minimum number in R Programming Language
- Find the position of minimum and maximum of value in R Programming Language
- Sort a vector in R Programming Language
- Multiplication Table in R Programming Language
- Fibonacci Sequence in R Programming Language
- Factorial of a number in R Programming Language
- Leap year or not in R Programming Language
- Check Armstrong number or Not in R Programming Language
- Find sum of natural numbers without/with formula using R Programming Language
- Find factors using R Programming Language
- Write a R Program to Find GCD
- Write a R Program to Find LCM