Comments (4)
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.
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.
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.
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)
- adorn_ns() adds excluded values to a adorn_totals() in a pipe HOT 3
- German transliterations in `make_clean_names()` HOT 4
- Feature suggestion: allow multiple rows input to `row_to_names()` HOT 16
- Feature Request: `paste_skip_na()` function that skips NA values when pasting HOT 4
- Feature suggestion: `most()` and `assert_count_true()` HOT 6
- Add paste_skip_NA to catalog vignette
- Edge case for `janitor::remove_emtpy()`: dataframe row dimension remains after columns removed HOT 1
- `get_one_to_one()` errors with duplicated dttm HOT 4
- Possible to enrich the get_dupes() HOT 1
- Upkeep proposition / spring cleaning HOT 10
- CRAN notification re: janitor/man/janitor.Rd
- Submit 2.3.0 to CRAN
- Remove `%>%` in favor of `|>`? HOT 5
- Set old names as labels in `clean_names` HOT 6
- Feature Request: A function for quick basic standardization of an otherwise tidy (almost) df HOT 2
- Feature request: A `rename`-like function that keeps the original names as an attribute HOT 1
- `cutoff` argument in `remove_empty()` is being implemented confusingly HOT 2
- Unexpected adorn_totals("col") HOT 1
- make_clean_names: Case conversions are wierd HOT 1
- [Feature Request] Allow `tabyl()` to accept character vectors as column names HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from janitor.