Why do we have to use data(spam) before we can run lda on it ? spam is a dataset in the ElemsStatLearn package.
library(ElemStatLearn)
library(MASS) # for lda
spam[5] # is ok
spam.lda = lda(spam ~ . , data = spam) # not ok
data(spam)
spam.lda = lda(spam ~ . , data = spam) # ok
We can access spam[5] even before we run data(spam).
R includes a range of datasets, mainly for use in examples. Some of these datasets are directly available (e.g.
irisorcars), in some packages they are not automatically available requiring a call todatato attach them to the current workspace, e.g.meusefrom thegstatpackage. So you experience inElemStatLearnis valid,spamis automatically available.