I have a data frame where all the variables are of character type. Many of the columns are completely empty, i.e. only the variable headers are there, but no values. Is there any way to subset out the empty columns?
相关问题
- R - Quantstart: Testing Strategy on Multiple Equit
- Using predict with svyglm
- Reshape matrix by rows
- Extract P-Values from Dunnett Test into a Table by
- split data frame into two by column value [duplica
相关文章
- How to convert summary output to a data frame?
- How to plot smoother curves in R
- Paste all possible diagonals of an n*n matrix or d
- ess-rdired: I get this error “no ESS process is as
- How to use doMC under Windows or alternative paral
- dyLimit for limited time in Dygraphs
- Saving state of Shiny app to be restored later
- How to insert pictures into each individual bar in
It depends what you mean by empty: Is it NA or
""
, or can it even be" "
? Something like this might work:If you know the column indices, you can use
This will omit columns 3, 5, 7.
If you're talking about columns where all values are
NA
, useremove_empty("cols")
from the janitor package.If you have character vectors where every value is the empty string
""
, you can first convert those values toNA
throughout your data.frame withna_if
from the dplyr package:I have a similar situation -- I'm working with a large public records database but when I whittle it down to just the date range and category that I need, there are a ton of columns that aren't in use. Some are blank and some are NA.
The selected answer: https://stackoverflow.com/a/17672737/233467 didn't work for me, but this did:
You can do either of the following:
or:
If by empty you mean they are
""
, the second approach can be adapted like so:Here is something that can be modified to exclude columns containing any variables specied.