Ivo: I may not get your question, but you seem to be confusing the name of an object, which is essentially a pointer into memory and a language construct -- (correction requested if I have misstated! -- and the "names" attribute of (some) objects. You can, of course, attach a "lab" or (whatever) attribute to an object that gives it a label and that will be carried around with it. But without special code (if it's at all possible, even) the label will know nothing about the name assigned to the object -- why should it?! i.e.
> y <- structure(1:3,lab = "y") > y [1] 1 2 3 attr(,"lab") [1] "y" > z <- y > z [1] 1 2 3 attr(,"lab") [1] "y Feel free to ignore without response if my comment is irrelevant. Cheers, Bert On Mon, Aug 19, 2013 at 9:45 AM, ivo welch <ivo.we...@anderson.ucla.edu> wrote: > dear R experts---I was programming a fama-macbeth panel regression (a > fama-macbeth regression is essentially T cross-sectional regressions, with > statistics then obtained from the time-series of coefficients), partly > because I wanted faster speed than plm, partly because I wanted some > additional features. > > my function starts as > > fama.macbeth <- function( formula, din ) { > names <- terms( formula ) > ## omitted : I want an immediate check that the formula refers to > existing variables in the data frame with English error messages > monthly.regressions <- by( din, as.factor(din$month), function(dd) > coef(lm(model.frame( formula, data=dd ))) > as.m <- do.call("rbind", monthly.regressions) > colMeans(as.m) ## or something like this. > } > > say my data frame mydata has columns named month, r, laggedx and ... . I > can call this function > > fama.macbeth( r ~ laggedx, din=mydata ) > > but it fails if I want to compute my x variables. for example, > > myx <- d[,"laggedx"] > fama.macbeth( r ~ myx) > > I also wish that the computed myx still remembered that it was really > laggedx. it's almost as if I should not create a vector myx but a data > frame myx to avoid losing the column name. I wonder why such vectors don't > keep a name attribute of some sort. > > there is probably an "R way" of doing this. is there? > > /iaw > > ---- > Ivo Welch (ivo.we...@gmail.com) > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.