Write an R Program for “Hello Geeks”

Hello, Beginner is the first basic program in any programming language. Let’s write the program in R programming language. All one needs to do is display the message “Hello World” on the screen. Let’s look at the program:

R Program to Print “Hello Beginner” using the print() function:

The following R program displays “Hello Beginner” in the output.

  • Declare a variable named “message” and assign the string “Hello Beginner” to it.
  • Use the “print()” function to display the value of the “message” variable, which is “Hello Beginner”.

This code declares a variable containing a message and then prints that message using the “print()” function in R.

R




# Print "Hello Beginner" message
 
message <-"Hello Beginner"
print(message)


Output

[1] "Hello Beginner"


Printing “Hello Beginner” using cat() function:

The following R program displays “Hello Beginner” in the output.

  • Declare a variable named “message” and assign the string “Hello Beginner” to it.
  • Use the “cat()” function to display the value of the “message” variable, which is “Hello Beginner”.

R




# Print "Hello Beginner" message
 
message <-"Hello Beginner"
cat(message)


Output:

[1] "Hello Beginner"

R Program to Print “Hello Beginner” using message() function:

R




message("Hello Beginner")


Output:

Hello Beginner

R Program to Print “Hello Beginner” using the sprintf() function:

R




name <- "Hello Beginner"
sprintf( name)


Output:

[1] "Hello Beginner"



Contact Us