Skip to content
Prev 317709 / 398506 Next

Handling NA values

Nothing comes to mind immediately for rowSums() or colSums() given the way in which they handle things, however using apply() you have more flexibility, albeit at the price of some speed:
[1]  0  3 NA

Essentially, if all elements in the row are NA's return NA otherwise return the sum of the non-NA elements.

Change the margin from 1 to 2 in apply() to use the same approach on columns.

Regards,

Marc
On Feb 16, 2013, at 12:22 PM, Christofer Bogaso <bogaso.christofer at gmail.com> wrote: