I have some import issues with a file, that create an empty column at the end such as :
library(data.table)
library(tidyverse)
MWE <- data.table(var1=c(1,2),var2=c(3,4),var3=c(NA,NA))
Now I can remove it easily as I know the empty column is the last one :
MWE2 <- MWE[,c(length(MWE)):=NULL]
But I wondered how I would do if I just wanted to remove a random empty column without knowing its number. A quick search here and on the datatable page gave me a lot of examples on how to :
- remove empty lines in datatables, through
na.omit
- remove empty columns in a dataframe, for instance here
But I did not find solutions to remove empty columns in datatables. What are the options and which is the fastest ?