R Advanced

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.

 

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.

Sorting the data

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

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.

That’s it.

Recent Posts

summary() Function: Producing Summary Statistics in R

The summary() is a generic function that produces the summary statistics for various R objects,…

2 weeks ago

R paste() Function

The paste() function in R concatenates vectors after converting them to character. paste("Hello", 19, 21,…

3 weeks ago

paste0() Function in R

R paste0() function concatenates strings without any separator between them. It is a shorthand version…

3 weeks ago

How to Calculate Standard Error in R

Standard Error (SE) measures the variability or dispersion of the sample mean estimate of a…

3 weeks ago

R max() and min() Functions

max() The max() function in R finds the maximum value of a vector or data…

4 weeks ago

R as.Date() Function: Working with Dates

The as.Date() function in R converts various types of date and time objects or character…

4 weeks ago