Coder Social home page Coder Social logo

Comments (6)

japhir avatar japhir commented on August 26, 2024

You could use dplyr's unite for this.

from isoreader.

sebkopf avatar sebkopf commented on August 26, 2024

good idea, I think what unite doesn't do well though is deal with NA - I imagine a scenario where you have e.g. info x from one type of IRMS format and info y from another but you want to work with them as a single id column: data_frame(x=c(NA, "a"), y = c("b", NA)) %>% unite(id, c(x, y)) creates NA_b and a_NA.

Maybe just a case_when would be easiest, that way the order the columns are provided also determines order of precedence. Maybe something like this with x, y, z dynamically implemented using the unite syntax?

data_frame(
 x=c(NA, "xb", "xc"), 
 y = c("ya", NA, NA), 
 z = c("za", "zb", "zc")) %>% 
mutate(
 id = case_when(
  !is.na(x) ~ x, 
  !is.na(y) ~ y, 
  !is.na(z) ~ z, 
  TRUE ~ NA_character_))

from isoreader.

japhir avatar japhir commented on August 26, 2024

Hmm in that case I don't understand what you want to achieve. This would always pick the first that has a non-na value and ignore further columns, right?

# A tibble: 3 x 4
  x     y     z     id   
  <chr> <chr> <chr> <chr>
1 NA    ya    za    ya   
2 xb    NA    zb    xb   
3 xc    NA    zc    xc   

from isoreader.

japhir avatar japhir commented on August 26, 2024

This discussion on tidyr's unite may be useful (on how to handle NA's). Maybe just replace the NA's with "", then unite the columns?

from isoreader.

sebkopf avatar sebkopf commented on August 26, 2024

actually implemented this with regular dplyr rename but executed for each isofile separately so recoding to the same column name is easy

from isoreader.

sebkopf avatar sebkopf commented on August 26, 2024

fully implemented in dev version with iso_rename_file_info() and iso_select_file_info() and supported in all iso_get... functions.

from isoreader.

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.