[R] Delete Columns with zeros

Uwe Ligges
2008-01-31T14:42:40Z

Jens Oldeland wrote:
> Hi,
>
> I know there have been some discussions on that topic. all their
> solutions failed in my case...
> My problem is that I have a dataframe with many zeros. but while
> plotting they are not useful.
> so I want to get rid of column 1,3,4,......,n i have 628 columns 1000
> rows, so I can?t look manually for the "empty" columns.
>
> Any possible Ideas?
>
>  > A250[1:5,1:4]
>
> AAPU ACTO ACRA ADBA
> A1100 0 0.0 0 0
> A20100 0 0.1 0 0
> A20200 0 0.0 0 0
> A400 0 1.0 0 0
> A4100 0 0.0 0 0
>
> I also didn?t find anything useful in "An Introduction to R".

  A250[, sapply(A250, function(x) any(x))]
  A250[, apply(A250, 2, function(x) any(x))]

Uwe Ligges



> thank you
>
> Jens
>