Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DimensionMismatch when checking if the cell value (not) belong to a collection #3316

Closed
mzy2240 opened this issue Apr 18, 2023 · 1 comment
Closed

Comments

@mzy2240
Copy link

mzy2240 commented Apr 18, 2023

using DataFrames

ids = [1,5,7,8,9]
a = DataFrame(A=1:3, B=4:6)
@. a.B = ifelse(a.A  ids, 0, a.B)
using DataFrames

ids = [1,5,7,8,9]
a = DataFrame(A=1:3, B=4:6)
@. a.B = ifelse(a.A  Ref(ids), 0, a.B)

Both will raise DimensionMismatch issue.

@bkamins
Copy link
Member

bkamins commented Apr 18, 2023

This is unrelated with DataFrames.jl. Use this instead:

julia> a.B .= ifelse.(a.A .∉ Ref(ids), 0, a.B)
3-element Vector{Int64}:
 4
 0
 0

see https://bkamins.github.io/julialang/2023/02/10/in.html for a detailed explanation.

@bkamins bkamins closed this as completed Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants