Giter Site home page Giter Site logo

Comments (3)

etiennebacher avatar etiennebacher commented on June 19, 2024 1

@rempsyc this works now:

library(datawizard)

df1 <- data.frame(
  id = c(1, 2, 3, 1, 3),
  item1 = c(NA, 1, NA, 2, NA),
  item2 = c(NA, 1, NA, 2, 3),
  item3 = c(NA, 1, 1, 2, 3)
)

dups <- data_duplicated(df1, "id")
dups
#>   Row id item1 item2 item3 count_na
#> 1   1  1    NA    NA    NA        3
#> 4   4  1     2     2     2        0
#> 3   3  3    NA    NA     1        2
#> 5   5  3    NA     3     3        1

good.dups <- data_group(dups, "id")

data_filter(good.dups, count_na == min(count_na))
#>   Row id item1 item2 item3 count_na
#> 4   4  1     2     2     2        0
#> 5   5  3    NA     3     3        1

Created on 2022-11-07 with reprex v2.0.2

from datawizard.

etiennebacher avatar etiennebacher commented on June 19, 2024

This works:

library(datawizard)

df1 <- data.frame(
  id = c(1, 2, 3, 1, 3),
  item1 = c(NA, 1, 1, 2, 3),
  item2 = c(NA, 1, 1, 2, 3),
  item3 = c(NA, 1, 1, 2, 3)
)

id <- "id"

dups <- data_duplicated(df1, id)

good.dups <- data_group(dups, id)

data_filter(good.dups, count_na == min(count_na))
#>   Row id item1 item2 item3 count_na
#> 4   4  1     2     2     2        0
#> 3   3  3     1     1     1        0
#> 5   5  3     3     3     3        0

Created on 2022-11-06 with reprex v2.0.2

from datawizard.

etiennebacher avatar etiennebacher commented on June 19, 2024

We don't have a data_filter.grouped_df() so the test above doesn't work if the minimum value in one group is not 0 (it should keep row 5 because it has only one NA):

library(datawizard)

df1 <- data.frame(
  id = c(1, 2, 3, 1, 3),
  item1 = c(NA, 1, NA, 2, NA),
  item2 = c(NA, 1, NA, 2, 3),
  item3 = c(NA, 1, 1, 2, 3)
)

id <- "id"

dups <- data_duplicated(df1, id)

good.dups <- data_group(dups, id)

data_filter(good.dups, count_na == min(count_na))
#>   Row id item1 item2 item3 count_na
#> 4   4  1     2     2     2        0

Created on 2022-11-06 with reprex v2.0.2

from datawizard.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.