Member-only story

How to Create Data Subsets in R Programming

Exploratory Data Analysis usually means creating subsets. Here are the key functions in R that are used for data exploration.

Pierre DeBois
6 min readFeb 16, 2023

When exploring data you import into R, you will want to work with sections of a dataset. Extracting these sections is called subsetting. There are several ways to subset your data within R programming, ranging from character usage to straightforward functions.

Index

The most common way is to use an index. An index in R is a single set of brackets alongside the name of a data object, with a number either before or after a comma within those brackets. The number is an index, identifying an element within the vector, list, or matrix.

RowExample1 <- X[2, ]

The number before the comma indicates that R returns an item from the row of the object. So as an example, I created a dataframe using the diamonds data in ggplot2 library. I then recreate the RowExample using the aforementioned indexing. The returned result is all the data in the second row of the example dataset, which is the second row of the diamond dataset.

--

--

Pierre DeBois
Pierre DeBois

Written by Pierre DeBois

#analytics |#datascience |#JS |#rstats |#marketing services for #smallbiz | #retail | #nonprofits Contrib @CMSWire @smallbiztrends #blackbusiness #BLM

Responses (1)