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

file.rename(): Renaming Single and Multiple Files in R

To rename a file in R, you can use the file.rename() function. It renames a…

15 hours ago

R prop.table() Function

The prop.table() function in R calculates the proportion or relative frequency of values in a…

20 hours ago

exp() Function: Calculate Exponential of a Number in R

The exp() is a built-in function that calculates the exponential of its input, raising Euler's…

21 hours ago

R split() Function: Splitting a Data

The split() function divides the input data into groups based on some criteria, typically specified…

1 week ago

colMeans(): Calculating the Mean of Columns in R Data Frame

The colMeans() function in R calculates the arithmetic mean of columns in a numeric matrix,…

2 weeks ago

rowMeans(): Calculating the Mean of rows of a Data Frame in R

The rowMeans() is a built-in, highly vectorized function in R that computes the arithmetic mean…

3 weeks ago