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