Perhaps you could explain the motivation behind this. At any rate here
are three different solutions:
ifelse(is.na(m1), ifelse(is.na(m2), NA, m2), ifelse(is.na(m2), m1, m1 + m2))
apply(array(c(m1, m2), c(2,2,2)), 1:2, function(x) sum(c(na.omit(x), NA)[1]))
na.m1 <- is.na(m1)
na.m2 <- is.na(m2)
On 29/01/2008, at 3:34 PM, Ng Stanley wrote:
> Hi,
>
> For example, given two 2x2 matrices m1 and m2. I would like to add/
> subtract
> element by element
>
>> m1
> [,1] [,2]
> [1,] NA NA
> [2,]12
>
>> m2
> [,1] [,2]
> [1,]1 NA
> [2,] NA2
>
>> m1 + m2
>
Hi,
For example, given two 2x2 matrices m1 and m2. I would like to add/subtract
element by element
> m1
[,1] [,2]
[1,] NA NA
[2,]12
> m2
[,1] [,2]
[1,]1 NA
[2,] NA2
> m1 + m2
[,1] [,2]
[1,] NA NA
[2,] NA4
How can I ignore the NA, and g
3 matches
Mail list logo