I'm doing what seems to be a simple exercise. I'm supposed to create a histogram of the ages on the passengers on the titanic. The data frame "titanic" is already spacified. Since age is the sixth variable (I checked) I write the following:
hist(titanic[6])
This does not seem to work for some reason. R generates an error message and tells med that "'x' must be numeric".
(The variable age is indeed numeric, I checked this both with the str()-function and by executing the titanic[6]-command outside of the function.)
Meanwhile I can write it like this without any problems:
hist(titanic$Age)
Why can I use one and not the other? When, in general, can I use brackets and when do I have to use the $-sign?