Uwe Freier
2022-Apr-26 18:10 UTC
[R] Confusing fori or ifelse result in matrix manipulation
Hello, many thanks for your replies. The code I've posted was simplified and depicted my problem basically. Of course my intention was not to add 0-columns to a matrix, the problem resulted from my approach to add only eigenvectors to a matrix if the corresponding eigenvalue is element of real numbers, otherwise 0. So now I've learned that following code does it: A is the matrix with the eigenvalues and -vectors of my interest M <- matrix(ncol=8,nrow=8)> for(i in 1:8) {M[,i] <- if(Im(eigen(A)$val[i]) == 0) eigen(A)$vec[,i] else 0 } Many thanks again! Uwe