Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to filter data in for loop based on external vector

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading