Thanks to Rolf Turner for his answer. The following function does
exactly what I want,
using assign():
myfun <- function()
{
set.seed(1)
assign("x", arima.sim(n = 100, model = list(ar = 0.9)), frame = 1)
model.1 <- lm(x[3:100] ~ x[2:99])
model.2 <- lm(x[3:100] ~ x[2:99] + x[1:98])
BIC(model.1, model.2)
}
I understand that assign is particularly useful, since you can specify
the exact location of
the object.
# ==============Part of the description of assign() ==================
DESCRIPTION
Assigns a value to a name. The location of the assignment can either be
a specific
frame (useful when writing functions), or a data directory.
USAGE
assign(x, value, frame=<<see below>>, where=<<see below>>, ...)
assign.default(x, value, frame=<<see below>>, where=<<see below>>,
immediate=F)
# ==========================================================
Thanks again,
--
Au plaisir, Pierre.
_____________________________________________________________________
Pierre Duchesne, professeur adjoint,
Service de l'enseignement des méthodes quantitatives de gestion (MQG)
École des Hautes Études Commerciales (http://www.hec.ca/mqg)
3000, chemin de la Côte-Sainte-Catherine, Montréal(QC) Canada H3T 2A7
Bureau: 4.821 Tél:(514)340-6503 Fax:(514)340-5634
Page WEB: http://www.hec.ca/profs/pierre.duchesne.html
=====================================================================
|