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.d
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 work
Hi:
Try this for your second loop instead:
for(s in school.list){
print(s)
print(subset(input.data, sch == s))
}
[1] 1
sch pop
1 1 100
2 1 200
[1] 2
sch pop
3 2 300
4 2 400
Don't confound the 'sch' variable in your data frame with the
index in your loop :)
HTH,
Dennis
On Mon,
I was surprised to see this unexpected behavior of subset in a for loop. I
looked in subset.data.frame and it seemed to me that both versions should
work, since the subset call should be evaluated in the global environment -
but perhaps I don't understand environments well enough. Can someone
enli
4 matches
Mail list logo