Reputation: 3191
This is probably a stupid question but, is there a way to define a dataset in R to save time by avoiding typing dataset$ before the names of all the variables over and over again?
E.g. so I would type :
varA<-varB+varC
instead of :
dataset$varA<-dataset$varB+dataset$varC
Thanks in advance.
Upvotes: 0
Views: 184
Reputation: 15441
attach()
is one way however,
transform
is a nice way to get rid of $
dat <- read.table(text = " varA varB varC
0 1 1
0 1 1
0 1 1", header=TRUE)
dat <- transform(dat, varA = varB + varC)
similar to mutate()
in plyr
which:
seems to be considerably faster than transform for large data frames.
Upvotes: 3
Reputation: 140589
attach(dataset)
but note that this is discouraged if you're writing code to be reused.
Upvotes: 2