R View() Function

The View() is a utility function in R that invokes a more intuitive spreadsheet-style data viewer on a matrix-like R object.

View() does not print output in the console or return a value — it is a side-effect function that launches a separate data viewer window. It is ideal for quickly checking data contents, identifying patterns, or verifying data integrity during data analysis workflows.

Syntax

View(x, title)

Ensure you type a capital “V” when using this function.

Parameters

Argument Description
x It represents an R object coerced to a data frame with non-zero numbers of rows and columns.
title

It is an optional character string specifying the title of the viewer window—defaults to “Data:” followed by the name of x.

Basic usage

Open RStudio. Create an R file and add the following code.

Open an RStudio

 

df <- structure(list(year = c(2016, 2017, 2018, 2019), 
                    length_days = c(365.32, 366.41, 366.53, 364.95)),
 .Names = c("year", "days"),
 class = "data.frame",
 row.names = c(NA, -4L))

View(df)

In this example, we create a data frame using the structure() function.

To see the output, run the above code inside RStudio, and it will give you the following output.

View() Function in R

Sorting the data

You can sort the data frame by clicking on one of the columns.

Sorting a data frame with View()

Filtering the data

You can filter the data frame by clicking the Filter icon, selecting a column name, and then entering a range of values.

Filtering the data frame

That’s it.

Leave a Comment