假设我的矩阵是
matrix( c(**2,2,2**,8,**2**,0,7,2,3) )
我需要输出
matrix( c(2,**0**,2,8,2,0,7,2,3) )
我正在尝试一些事情。示例代码:
initialize matrix
A = matrix( c(2,2,2,8,2,0,7,2,3), nrow=3,ncol=3, byrow = TRUE)
parsing matrix
for(i in 1:dim(A)[1])
{
for(j in 1:dim(A)[2])
{
checking adjacent
if (A[i]==A[i+1] & A[i]==A[j+1] )
{
A[i]=0
}
}
}