Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] as.data.frame() method for Categories objects #635

Open
rossellhayes opened this issue Jan 23, 2024 · 3 comments
Open

Comments

@rossellhayes
Copy link
Contributor

Including an as.data.frame() method for Categories objects would make it easier to use join functions to map between the names and numeric codes associated with a variable.

Here are the functions that I'm currently using in my scripts to achieve this:

as.data.frame.Category <- function(category) {
  data <- category@.Data
  names(data) <- category@names
  data[lengths(data) == 0] <- NA
  as.data.frame(data)
}

as.data.frame.Categories <- function(categories) {
  do.call(rbind, lapply(categories@.Data, as.data.frame))
}
@gergness
Copy link
Contributor

gergness commented Jan 29, 2024

Yeah, seems like an oversight because there is one for variables.

A complication I can foresee would be that I don't think the category metadata schema is consistent between variables. Do you think numeric_value or datetime column should always be present, or only when relevant?

@rossellhayes
Copy link
Contributor Author

I think my expectation would be that an as.data.frame() method would produce a data frame that looks like the print method for Categories objects, i.e. only including the columns that are relevant for that variable type, but I would be happy with either implementation!

@1beb
Copy link
Contributor

1beb commented Jun 14, 2024

I think I have a method for this already in crunchtabs. I think it's in codebook. https://github.com/Crunch-io/crunchtabs/blob/main/R/codeBookSummary.R#L137

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants