Connect with us

Hi, what are you looking for?

Programming

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. Required fields are marked *

You May Also Like

Programming

This article is prepared to explain concepts that will be important for programming beginners such as data types, variables, heap and stack, and operators....

Programming

This article was created for those who want to use functional programming in their career or who are learning new programming paradigms. We will...

Programming

Functions are pieces of code that combine the integrity of the code used to perform a task into a single structure. If you are...

Programming

Computers can solve an event in different ways, we call these ways algorithms, each algorithm works differently from the others and has different processing...