How To View Values In R

Viewing values in R is an essential skill for anyone working with data.

Whether you’re exploring a dataset or checking the output of a function, being able to view values helps you understand the data you’re working with. In this tutorial, you’ll learn how to view values in R using a variety of techniques.


1. Print Values to the Console

The simplest way to view values in R is to print them to the console. To do this, you can use the print() function or simply type the name of the variable. For example:


As you can see, both print(x) and x output the value of the variable x.

2. View Values in Data Frames

If you’re working with data frames, you can use the View() function to view the data in a spreadsheet-like interface. For example:

This will open a new window with the data frame displayed in a spreadsheet format. You can sort and filter the data in this view, making it a useful way to explore your data.

3. View Values in Plots

If you’re working with visualizations in R, you can use the plot() function to view the data in a graphical format. For example:

This will create a scatter plot of the cars data, with speed on the x-axis and stopping distance on the y-axis. You can customize the plot with options like main for the title, xlab for the x-axis label, and ylab for the y-axis label.

4. Export Values to Files

If you want to export values from R for use outside of R, you can use functions like write.csv() or write.table() to export data frames to CSV or text files. For example:

This will export the data frame to a CSV file named “data.csv” in your working directory.


Viewing values is an essential skill for anyone working with data in R. By using techniques like printing to the console, viewing data frames in a spreadsheet, creating visualizations with plots, and exporting data to files, you can better understand and work with your data in R.