On Wednesday 27 December 2006 06:00, r-help-request at stat.math.ethz.ch
wrote:> jingjiangyan
I agree, you can use 'assign'. To be more explicit, you could use the
following function.
jingjiangyan <-
function(formula, data)
{
m <- match.call()
"%,%" <- function(x,y)paste(x,y,sep="")
d.nm <- as.character(m$data)
y.nm <- as.character(formula[[2]])
x.nm <- as.character(formula[[3]])
for(i in levels(data[[x.nm]])){
var.name <- d.nm %,% "." %,% i
var.val <- data[[y.nm]][data[[x.nm]]==i]
cmd <- var.name %,% " <- " %,% var.val
eval(cmd)
assign(var.name, var.val, globalenv())
}
}
Next, assuming the data.frame listed in the previous posting, 'df'
exists in your workspace, the call
jingjiangyan(bb ~ aa, data=df)
would produce the desired results.
Cheers,
Grant Izmirlian
--
????? ?????????