I have installed Janitor package to use the remove_empty_cols() function to remove columns in my data frame that have all NAs.
test_no_na <- remove_empty_cols(test_dataframe)
I have searched a ton on other ways to do this and everything seems a lot more complicated so was hoping I could use this package. Open to other suggestions.
I don't understand your problem, remove empty()
function works as expected for me.
library(janitor)
df <- data.frame(col1 = c(NA, NA, NA, NA, NA),
col2 = c(NA, 2, 3, 4, 5)
)
df
#> col1 col2
#> 1 NA NA
#> 2 NA 2
#> 3 NA 3
#> 4 NA 4
#> 5 NA 5
remove_empty(df, which = c("rows"))
#> col1 col2
#> 2 NA 2
#> 3 NA 3
#> 4 NA 4
#> 5 NA 5
remove_empty(df, which = c("cols"))
#> col2
#> 1 NA
#> 2 2
#> 3 3
#> 4 4
#> 5 5
remove_empty(df)
#> value for "which" not specified, defaulting to c("rows", "cols")
#> col2
#> 2 2
#> 3 3
#> 4 4
#> 5 5
Created on 2019-01-16 by the reprex package (v0.2.1)
ugh. thank you. newbie error. i installed package but didn't load library. one more silly question: how do you copy in code snippets here?
In this FAQ you will find how to do reproducible examples like that one.
Why reprex?
Getting unstuck is hard. Your first step here is usually to create a reprex, or reproducible example. The goal of a reprex is to package your code, and information about your problem so that others can run it and feel your pain. Then, hopefully, folks can more easily provide a solution.
What's in a Reproducible Example?
Parts of a reproducible example:
background information - Describe what you are trying to do. What have you already done?
complete set up - include any library() calls and data to reproduce your issue.
data for a reprex: Here's a discussion on setting up data for a reprex
make it run - include the minimal code required to reproduce your error on the data…
If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:
If your question has been answered, don't forget to mark the solution!
How do I mark a solution?
Find the reply you want to mark as the solution and look for the row of small gray icons at the bottom of that reply. Click the one that looks like a box with a checkmark in it:
[image]
Hovering over the mark solution button shows the label, "Select if this reply solves the problem". If you don't see the mark solution button, try clicking the three dots button ( ••• ) to expand the full set of options.
When a solution is chosen, the icon turns green and the hover label changes to: "Unselect if this reply no longer solves the problem". Success!
[solution_reply_author]
…
system
Closed
January 23, 2019, 11:04pm
6
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.