R Print Output

R Tutorial

 R Print Output – Complete Guide

In R Print Output means displaying values, variables, or results on the screen.


 1. Using print() (Basic & Most Common)

Output:

[1] "Hello World"
  •  Explicit way to display output
  •  Works everywhere (scripts, functions, loops)

 2. Printing Variables

Output:

[1] 10

 3. Printing Without print() (Interactive Use)

Output:

[1] 25
  •  Works in R Console / RStudio, but
  • NOT reliable inside functions or scripts

 4. Printing Multiple Values

Output:

[1] 10 20

 5. Printing Text and Variables Together

 Wrong way

 Correct way – paste()

Output:

[1] "Value is 50"

 6. Using cat() (Clean Output – No Quotes)

Output:

Value is 100
  •  No quotes
  •  No [1]
  •  Best for user-friendly messages

 7. Difference: print() vs cat()

Featureprint()cat()
Shows quotesYesNo
Shows index [1]YesNo
Multiple valuesYesYes
Best forDebuggingUser output

 8. Printing Data Structures

Vector

List

Data Frame


 9. Printing Inside Functions (Important)


 

  •  Without print(), output will NOT show inside functions

 10. Printing with New Line

Output:

Hello
World

 11. Printing with Formatting

Output:

Value is 12.35
  •  Controls decimal places
  •  Useful in reports

 12. Common Beginner Mistakes

  •  Forgetting print() inside functions
  • Using print() for clean text output
  • Mixing print() and cat() incorrectly

 13. Interview Questions (Must Know)

Q1: Difference between print() and cat()
print() shows structure
cat() shows clean output

Q2: Why [1] appears in R output?
 It shows index position


 Quick Cheat Sheet


You may also like...