0

I have a rather basic and simple question. I was not able to find a solution anywhere in this forum, partly maybe also due to the fact that searching for symbols like "[]" and "$" is difficult in Google.

In any case, I have come across 2 different ways to address columns in data frames. Consider data frame df and column c1. I can address this column as follows:

df[,"c1"]
df$c1

I initially used the syntax with $, however now moved to [] because the former did not work in some cases.

Now my question: are these 2 syntax equivalent? Where is the difference? In which cases in any of them better?

Thanks, Martin

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
deca
  • 730
  • 1
  • 8
  • 24
  • 3
    Your question is answered in the documentation, which you can access via: `help("Extract")`, `help("[")`, or `help("$")` (all 3 commands will take you to the same documentation). – Joshua Ulrich Aug 29 '16 at 16:09
  • The linked question may not be exactly the same, but the accepted answer there will answer your question. – Rich Scriven Aug 29 '16 at 16:17

0 Answers0