FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Create a data.table when one vector is transposed doesn't respect the name defined by user · Issue #4124 · Rdatatable/data.table · GitHub

Create a data.table when one vector is transposed doesn't respect the name defined by user #4124

Description

This is a minor issue, but I didn't expect this behavior:

# Create some dummy data:
library(data.table)
a <- as.data.table(matrix(1:4, ncol = 4))
a[, V1 := "x"]
setnames(a, 2:4, letters[2:4])

# make a new data.table out of the first one, transposing one of the vectors:
b <- data.table(name = names(a)[2:4], value = t(a[, 2:4]))

# produces:
b
    name value.V1
 1:    b        2
 2:    c        3
 3:    d        4

I didn't expect my defined name value would become value.V1.

I'm aware I could have done b <- melt(a, 1)[, 2:3] (and then rename the first column) to obtain the correct result.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL