How to filter data in for loop based on external vector

49 Views Asked by At

I'm trying to create for loop based on external vector and my expectation is to create aa_loop which is prefiltered based on uni input (for test only). Why below code doesn't produce aa_loop or how to do it in a proper way?

names = ["Sally", "Bob", "Alice", "Hank"]
grades = [1, 5, 8.5, 4]
aaa = DataFrame(name=names, grades=grades)

#for test only
uni = "Bob"

for nm in uni
    aa_loop = subset(aaa,  :name => ByRow(==(nm)))
end
1

There are 1 best solutions below

1
DNF On BEST ANSWER

Iterating over a string produces characters, so for nm in uni will produce 'B', then 'o' and then 'b'. Try putting uni in a container, like for nm in (uni,) or for nm in [uni]