Skip to content

Behaviour of df[condition, "colname"] <- value differs for tibbles and data frames #846

@hongooi73

Description

@hongooi73

When the condition in a subsetting assignment is entirely FALSE, this expression results in a column of NAs for a data frame, and no additional column for a tibble.

For a data frame:

df <- data.frame(a=1:3)
df[df$a < 0, "b"] <- 1
  a  b
1 1 NA
2 2 NA
3 3 NA

For a tibble:

tbl <- tibble(a=1:3)
tbl[tbl$a < 0, "b"] <- 1
# A tibble: 3 x 1
      a
  <int>
1     1
2     2
3     3

Is this intended behaviour?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions