print()

print()

The print() function will print out, or make visible in the output, any contents in the argument. 

Example 1:

The print() function can be helpful for annotating code output. Put content in "quotations" to avoid error messages.

print("Analysis of Variance")
print("p = 0.02")

Example output:

Output of print function

Example 2:

You can also use the print() function to printout the contents of a data frame.

# print an entire data frame
print(MindsetMatters)

Example of output from running the code above (truncated):

Output of print function with the MindsetMatters data frame

# print a single column (variable) of a data frame
print(MindsetMatters$Age)

Example of output from running the code above:

Output of the print function with the MindsetMatters data frame and the Age variable

    • Related Articles

    • Printing Pages of the Book

      If you need to print pages of the book, you may find that printing them from Chrome results in oddly-formatted pages.  You will get better-formatted pages if you print using either Safari or Firefox as your browser. If using Safari, go the the Safari ...
    • tail()

      The tail() function is used to get the last rows of a vector or data frame. By default, it will print out the last 6 rows of the object, but you can also specify the number of rows you would like to print out. The tail() function is similar to the ...
    • head()

      The head() function is used to get the first rows of a vector or data frame. By default, it will print out the first 6 rows of the object, but you can also specify the number of rows you would like to print out. The head() function is similar to ...
    • sample()

      The sample() function will take a random sample of rows from the data frame, without replacement (of the specified sample size).  For random sampling with replacement, see the resample() function. Example 1: You can take a closer look at how the ...
    • resample()

      The resample() function will take a random sample of rows from the data frame, with replacement (of the specified sample size). It can be useful if you want to bootstrap a sampling distribution of statistics (e.g., b1, PRE, F) (Bootstrapping ...