On Tue, 2 Feb 2010, David Katz wrote:
Thanks, that helps! Subset creates a new context where a name clash can occur. So if I don't want to check for that possibility, I should use a special kind of index like .sch, or avoid subset: for(sch in school.list){ print(sch) print(input.data[input.data[,school.var] == sch,])} which works no matter what variable names I use. That seems like a reasonable requirement for good code. (Checking for a name clash would be at least theoretically needed since school.var is a parameter that can be any character name.) Although subset conveniently avoids extra typing in many cases (not here), this suggests to me that it's not ideal for code that can be used in a variety of contexts. Note that unlike "attach", subset does not issue a warning!
attach() doesn't issue a warning for this situation, it warns when a variable in the data set *fails to* mask one in the global environment. subset() can't fail to mask variables further up the search path, so it doesn't ever warn. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.edu University of Washington, Seattle ______________________________________________ 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.