[R] Exclude NA while summing

R. Michael Weylandt michael.weylandt at gmail.com
Thu Nov 17 14:41:47 CET 2011


Or, for this specific application

rowSums(XXX, na.rm = TRUE)

Michael

On Thu, Nov 17, 2011 at 5:51 AM, Jim Holtman <jholtman at gmail.com> wrote:
> change to
>
>> row.sums.m <- apply(dummy.curr.res.m,1,sum, na.rm = TRUE)
>
> Sent from my iPad
>
> On Nov 17, 2011, at 5:18, Vikram Bahure <economics.vikram at gmail.com> wrote:
>
>> Dear R users,
>>
>> I am new to R and have some query.
>>
>> I am having a dataset with binary output 0's and ones. But along with it it
>> has NA's too. I want to sum all the rows and get the sum total for each
>> column.
>>
>> But whenever there is a NA in an row the sum of the row is returned as NA
>> so I am not able to sum up the values.
>>
>> *row.sums.m <- apply(dummy.curr.res.m,1,sum)*
>>
>> It would be helpful if I get some input on this.
>>
>>
>> Regards
>> Vikram
>>
>>    [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> 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.
>
> ______________________________________________
> 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