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

mutate doesn't handle complex values #436

Closed
baptiste opened this issue May 23, 2014 · 12 comments
Closed

mutate doesn't handle complex values #436

baptiste opened this issue May 23, 2014 · 12 comments
Assignees
Labels
Milestone

Comments

@baptiste
Copy link

@baptiste baptiste commented May 23, 2014

I often used mutate in plyr to split a complex variable into real and imaginary parts before plotting them. It seems that dplyr::mutate chokes on complex values

require(dplyr)

d <- data.frame(x=1:10, y=1:10+2i)
mutate(d, real=Re(y), imag=Im(y))
# Error: unsupported type for column 'y' (CPLXSXP)
@noamross
Copy link

@noamross noamross commented Jul 25, 2014

group_by() gives the same error.

Loading

@hadley hadley added this to the 0.3 milestone Jul 28, 2014
@hadley
Copy link
Member

@hadley hadley commented Jul 28, 2014

@romainfrancois can we add hashing etc. for complex vars?

Loading

@hadley hadley added this to the 0.3.1 milestone Sep 12, 2014
@hadley hadley removed this from the 0.3 milestone Sep 12, 2014
@romainfrancois
Copy link
Member

@romainfrancois romainfrancois commented Oct 1, 2014

Done mutate, moving on to filter which segfaults for now:

> filter( d, x < 4 )

 *** caught segfault ***
address 0x0, cause 'memory not mapped'

Loading

romainfrancois added a commit that referenced this issue Oct 1, 2014
@romainfrancois
Copy link
Member

@romainfrancois romainfrancois commented Oct 1, 2014

@hadley do we need to be able to join complex and other types, i.e. currently it would give:

> inner_join(a, b, by = "x" )
Erreur : cannot join on columns 'x' x 'x' : Can't join on 'x' x 'x' because ...
 of incompatible types (complex/numeric)

Could make complex/int, complex/numeric, numeric/complex, int/complex work. But not sure it is worth the effort. @baptiste ?

Loading

@romainfrancois
Copy link
Member

@romainfrancois romainfrancois commented Oct 1, 2014

Apart from that, I think most dplyr verbs now support complex data. So I'm closing this. Please reopen if I'm wrong.

Loading

@hadley
Copy link
Member

@hadley hadley commented Oct 1, 2014

If any one needs that, they can file an issue.

Loading

@baptiste
Copy link
Author

@baptiste baptiste commented Oct 1, 2014

Thanks! I'm happy already with mutate and summarise personally. Also, I'm not sure what a, b, and x are in the inner_join example above?
I'm a bit concerned by the logic with arrange and the underlying comparison operator; does it even make sense to attempt ordering complex numbers, one way or another? Math says no.

Loading

@romainfrancois
Copy link
Member

@romainfrancois romainfrancois commented Oct 1, 2014

@baptiste R does provide a sort :

> sort( 1:10 + 10:1*1i)
 [1]  1+10i  2+ 9i  3+ 8i  4+ 7i  5+ 6i  6+ 5i  7+ 4i  8+ 3i  9+ 2i 10+ 1i

Anyway, I needed this to avoid redesigning the whole thing and take comparisons out of the VectorVisitor classes, etc ...

FYI; a, b and j are like this:

 a <- data.frame(x = c(1, 1, 2, 3)*1i, y = 1:4)
 b <- data.frame(x = c(1, 2, 2, 4), z = 1:4)
 j <- inner_join(a, b, "x")

Glad you like it; the issue has been sitting there for some time now.

@hadley I don't think this clashes with anything on the master branch. I'll let you decide if you want this in 0.3 or not. For now the dev_0_3_1 branch has only been about that issue.

Loading

@baptiste
Copy link
Author

@baptiste baptiste commented Oct 1, 2014

@romainfrancois fair enough, i forgot that R did such a thing. ?order mentions it, and so should ?arrange in my opinion: "Complex values are sorted first by the real part, then the imaginary part."

I haven't tried the mutate code yet, I'm assuming it just works :)

Loading

@hadley
Copy link
Member

@hadley hadley commented Oct 1, 2014

@romainfrancois it probably is fine to merge, but I think it's easier for me to manage the release process if we keep everything separate for now. I think we should plan for dplyr 0.3.1 in about a month - I'm sure there will be other issues that crop up after wider dissemination.

Loading

@kevinushey
Copy link
Contributor

@kevinushey kevinushey commented Oct 1, 2014

Complex values should be sorted by projecting them onto a unit circle and getting the order around that circle ;)

Loading

@baptiste
Copy link
Author

@baptiste baptiste commented Oct 1, 2014

@kevinushey that would certainly win the argument

Loading

@lock lock bot locked as resolved and limited conversation to collaborators Jun 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants