0

I'm new to R so this might be a dumb question but can someone help me out clarifying the $ function in R please? I know that $ is used to extract a specific "part" from the data frame. Is it correct that it is extracting one whole column of the data frame? not a specific element in the column nor one whole specific row? The $ sign only worked for me when the variables were as columns. Is this correct?

Tried manipulating the data frame to see different results.

chunguc1004
  • 111
  • 1
  • 1
    Yes, it extracts a single column in a data.frame/tibble/data.table or an element in a `list` (using name). The only condition is that they are `list`. A data.frame or tibble or data.table are all subsets of list with some additional attributes.. Regarding the different results, we don't know your code or the example to test. But, `iris$Species` or `iris[["Species"]]` or `iris[[5]]` all returns the Species column – akrun Feb 10 '23 at 18:26
  • 1
    See https://stackoverflow.com/q/1169456/3358272 for `[`-vs-`[[` and some `$` discussion, and https://stackoverflow.com/q/18222286/3358272 for some more discussion on `$`. – r2evans Feb 10 '23 at 18:28

0 Answers0