Connect with us

Hi, what are you looking for?


Subsetting In R Programming (1)

In this tutorial, we going to look at subsetting in R. R language is so important for data science and this tutorial is a helper for R. If you didn’t read Data Types In R, you can read to prepare.

What Is Subsetting?

Subsetting is a useful indexing function for accessing object elements. For example, we have a list and we want to access the first index in the list, we can use subsetting to access this object. I gave the example Pseudocode below. If you don’t know Pseudocode, you can read the documentation in Wikipedia for this, click the Pseudocode link.

Subsetting Pseudocode
List = [1 , 2 , 3 , 4]
List[1] # Access first index

If you don’t understand the above syntax don’t worry we going to examine a lot of examples.

Subsetting Basic Infos

In this part, we going to look at subsetting in vectors so we going to make a simple vector and we subsetting in this vector. If you don’t know vectors you should read Data Types In R, because if you don’t know data types you can’t work with vectors.

Above, firstly, we create a new vector after that we call the first index in the vector so, the value you write in square brackets pulls data from the section in the region you specify. For example, if we wrote the index as 3, we would get the result 3.

Sometimes we need to call multiple data, for this, we can use multi-index, let’s look at this multi-index.

Above, we create a new vector and we are calling indexes 1 to 4. Now, we going to learn to call index by value.

If you assign these indexes to a variable, it will be printed as a bool type, but if it is used as an index of the vector, it will return to its old value like the final output.

Subsetting – Lists And Matrix

Anymore, we know basic subsetting properties, now we going to learn subsetting with lists and matrix. If you don’t know Lists or Matrix you should read Data Types In R.

You can call index in a list with the above methods. Now, we going to look at these methods.

$ syntax -> Used to call variables in a set. (you can’t call normal index you can call variable from set)

X [[“variable”]] -> Used to call variables in a set (you can’t call normal index you can call variable from set)

Anymore we know how to use subsetting with a list, now, we going to pass Matrix subsetting. Before you start, try to create your own examples of past topics.

Congratulations, You Passed Subsetting In R – 1
Click to comment

Leave a Reply

Your email address will not be published.

You May Also Like

Cyber Security

TCP/IP is a set of rules that allow computers to communicate with each other on a network such as the Internet. Currently, we do...

Cyber Security

Search engines are filled with more and more data and information every day. Search engines are your best friend when you want to gather...


According to a study from Dartmouth College, Dartmouth’s Tuck School of Business, and Indiana University, artificial intelligence systems can be trained to produce human-like...

Cyber Security

There is a systematic order (layer ordering) in networks for data transfer to occur. These layers are responsible for transmitting the data to the...