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

I cannot use @select statement in base/tidier

I’m trying to use select statement but in both examples I’m getting an error message ERROR: LoadError: UndefVarError: @select not defined. Do you know what may causes that?

#DF
names = ["Sally", "Bob", "Alice", "Hank"]
grades = [1, 5, 8.5, 4]
df = DataFrame(; name=names, grades=grades)

#Base
@chain df begin
    @transform(:grades_new = :grades/2)
    @subset(:name .== "Sally")
    @select(:grades)
end

#Tidier
@chain df begin
    @mutate(grades_new = grades/2)
    @filter(name == "Sally")
    @select(grades)
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

There is a conflict with DataFramesMeta.@select and Tidier.@select.
Use:

using DataFrames, Chain, DataFramesMeta, Tidier

#DF
names = ["Sally", "Bob", "Alice", "Hank"]
grades = [1, 5, 8.5, 4]
df = DataFrame(; name=names, grades=grades)

#Base
@chain df begin
    @transform(:grades_new = :grades/2)
    @subset(:name .== "Sally")
    DataFramesMeta.@select(:grades)
end
#1×1 DataFrame
# Row │ grades  
#     │ Float64 
#─────┼─────────
#   1 │     1.0

@chain df begin
    @mutate(grades_new = grades/2)
    @filter(name == "Sally")
    Tidier.@select(grades)
end
#1×1 DataFrame
# Row │ grades  
#     │ Float64 
#─────┼─────────
#   1 │     1.0
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