[R] Remove zero row from data.frame
Uwe Ligges
ligges at statistik.uni-dortmund.de
Fri Oct 5 11:58:43 CEST 2007
Rees, David wrote:
> Hi,
>
> Sorry that this is such a basic question, but I am having trouble with
> the following.
>
> I would like to remove all rows where the data is all zeros in a
> data.frame such as the following
>
>> x
> date a b c
> 1 2007.09.25 99.89844 100.0586 100.0840
> 4 2007.09.26 99.89844 100.0586 100.0801
> 7 2007.09.27 0.00000 0.0000 0.0000
> 10 2007.09.28 99.89648 100.0391 100.0664
> 13 2007.10.01 99.88672 100.0254 100.0566
Just one example:
x[rowSums(x[,-1]^2) > 0, ]
Uwe Ligges
> i.e. in this example remove the 3rd row.
>
> There could several, or no row with zeros, and in this example there are
> only 4 columns, but in general there are several hundred (so hopefully
> no typing of "a", "b", "c" or "x$a", "x$b" etc.)
>
> Many thanks in advance for any help.
>
> Regards,
> D
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list