Janitor: remove_empty() or remove_empty_cols() not appearing

#1

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.

0 Likes

#2

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)

0 Likes

#3

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?

0 Likes

#4

In this FAQ you will find how to do reproducible examples like that one.

0 Likes

#5

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:

0 Likes

closed #6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

0 Likes