I have a data set of dimension 401*5677. Among the column of this matrix there are columns which are identical but under different column names. Now, I want to keep only one
try duplicated function on transpose of the matrix.
duplicated.columns <- duplicated(t(your.matrix))
new.matrix <- your.matrix[, !duplicated.columns]
One line answer
B = matrix(c(1, 4, 0, 2, 56, 7, 1, 4, 0, 33, 2, 5), nrow = 3)
colnames(B) <- c("a", "b", "c", "d")
B
## a b c d
## [1,] 1 2 1 33
## [2,] 4 56 4 2
## [3,] 0 7 0 5
B[, !duplicated(t(B))]
## a b d
## [1,] 1 2 33
## [2,] 4 56 2
## [3,] 0 7 5