$ symbol in R || $ function in R programming language

$ symbol in R || $ function in R programming language

Hello guys, what’s up? I have found that many of you are searching about $ symbol in r. It’s quite easy. Let’s start—

In R programming language, there are 4 forms of the extract operator. Those are [, [[, $, and @. 

·         [, can be used to extract content from vectors, lists, or data frames. 
·         [[ and  $, extract content from a single object.
·         @ is  the slot operator also known as a formally defined object in R, which is used to extract content from objects built with the S4 object system

Here I am not discussing about the entire operator. I just clarify you what is $ symbol in r with proper example.
As earlier what I have told, $ is used to extract content from a single object. Then means it is used to refer to an element in a list or a column in a data frame.

We often want to select an entire column, namely one specific variable from a data frame. If we want to select all elements of the variable diameter, we can just write this—

Or you can write like below—
nameOf_dataframe[,positionOf_colomn]  nameOf_dataframe[,”nameOf_colomn”]

Theoretical Explanation:

Assuming that, we have a data frame called ‘hi and it has 3 columns:
                                1. John
                                2. Faizi
                                3. Clark
        AND also assuming that we enter the command just like below:

        Then it returns all of the values in the column labeled john. Assuming that the numbers are the actual column numbers, we can get the same result by calling:

        hi[, 1]

        It returns all values in column index position ‘1’.

        Code Example 1:
        Mylist = list (x=1, y=42)

        After execution of it, it will print 42

        Code Example 2
        x <- list(a=1, b=2, c=3)
        # [1] 2

        So, guys, that’s all about $ symbol in r. Later we will discuss another topic of r programming language. Till then, take care. Happy Coding

        Post a Comment