Giter Club home page Giter Club logo

Comments (4)

sfirke avatar sfirke commented on June 14, 2024

Would this be a function that converts all factor columns to characters? There's a purrr one-liner that seems to do that:
df %>% map_if(is.factor, as.character) -> df
(from here)

Would the function be more than that?

from janitor.

almartin82 avatar almartin82 commented on June 14, 2024

Yeah, that's basically what I've been doing. It's been more challenging
than that one liner because I have been working with the mdb-get function
from Hmisc, which puts these S3 labels on every data frame... dmap_if
doesn't like it at all. See
https://github.com/almartin82/nyschooldata/blob/master/R/assess_db.R#L57
for more. Maybe this is just an edge case though.

On Aug 2, 2016 9:23 PM, "Sam" [email protected] wrote:

Would this be a function that converts all factor columns to characters?
There's a purrr one-liner that seems to do that:
df %>% map_if(is.factor, as.character) -> df
(from here
http://stackoverflow.com/questions/2851015/convert-data-frame-columns-from-factors-to-characters
)

Would the function be more than that?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#49 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAvvNy7AKFEDFhfI808Wq4IzVCdlV2gaks5qb-2KgaJpZM4Jaixk
.

from janitor.

sfirke avatar sfirke commented on June 14, 2024

Is the Hmisc labelled class the same one produced by haven::read_sav()? I and a colleague both often want to go labelled -> factor. I used to have a janitor function for that, but I removed it. it felt too niche and I thought it might make haven a requirement of the package, though I'm new to understanding that part of package development. If a similar function would solve both of our problems, and it's a widespread issue with a non-trivial solution, I think a solution could be within scope.

My function was basically:

  labeled_var_index <- unlist(
    lapply(labels_df, function(x) class(x) == "labelled")
  )
  factorized <- labels_df
  factorized[, labeled_var_index] <- lapply(factorized[, labeled_var_index], as_factor)

from janitor.

sfirke avatar sfirke commented on June 14, 2024

I haven't worked with it a ton yet but the sjlabelled package looks pretty robust for dealing with factor conversions. At this point I'd be surprised if this kind of functionality doesn't already exist elsewhere. Closing this as I clean up issues a bit.

from janitor.

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.