lundi 31 octobre 2016

return a matrix with ifelse in R

I have two matrices:

mat<-matrix(1:6,2,3)
mat2<-matrix(1:2,2,3)

and a parameter

a<-1

using ifelse, is it possible to return a matrix when a is a certain value? the code that I am using, does not work: e.g.

mat.new<-ifelse(a==1,mat,mat2)

Aucun commentaire:

Enregistrer un commentaire