Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove empty columns in R?

Tags:

r

csv

I have a CSV file

Identity,Number,Data,Result,Add,,,,,,,,,,,,
1,,,,4,55,,92,,,,,,,,,62,
3,,,,7,43,,12,,,,,,,,,74,
7,,,,3,58,,52,,,,,,,,,64,
0,,,,6,10,,22,,,,,,,,,96,
3,,,,8,13,,92,,,,,,,,,22,

How to remove empty columns in R?

Desired Output

Identity,Number,Data,Result,Add
1,4,55,92,62
3,7,43,12,74
7,3,58,52,64
0,6,10,22,96
3,8,13,92,22
like image 504
user3188390 Avatar asked Feb 28 '14 20:02

user3188390


1 Answers

After you've imported your data (using the method the other answerer suggested) run this command, substituting mydf for whatever you decide to call your data frame:

#Remove empty columns
mydf <- Filter(function(x)!all(is.na(x)), mydf)
like image 147
americo Avatar answered Sep 30 '22 16:09

americo