Skip to content

as.data.table() returns a 1 column matrix when the matrix columns are factors #868

Closed

Description

@mgahan

Here is some sample data
iris <- data.table(iris)

This code produces a one column vector when Species is a factor.
as.data.table(combn(unique(iris$Species),2))

V1
1: setosa
2: versicolor
3: setosa
4: virginica
5: versicolor
6: virginica

While this code produces a matrix.
as.data.table(combn(unique(as.character(iris$Species)),2))

V1 V2 V3
1: setosa setosa versicolor
2: versicolor virginica virginica

Issue found through SO question here:
http://stackoverflow.com/questions/26244685/r-count-every-possible-pair-of-values-in-a-column-grouped-by-multiple-columns/26246588?noredirect=1#comment41177317_26246588

Activity

  1. arunsrinivasan commented on Oct 8, 2014

    @arunsrinivasan
    Member

    @mgahan 👍 thank you.

  2. added this to the v1.9.6 milestone on Feb 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions