KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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 column from the columns which are repeated more than once, and also get the index j for the columns removed. Let us use as an example matrix, the following: B=matrix(c(1,4,0,2,56,7,1,4,0,33,2,5), nrow=3) colnames(B)<-c("a","b","c","d") What I did so far (on my real matrix G) is: corrG<-cor(G) Gtest=G for (i in 1:nrow(corrG)){ for (j in 1:ncol(corrG)){ if (i<j && corrG[i,j]==1){ Gtest[,j]=NA } } } Gfinal<-Gtest[,complete.cases(t(Gtest))] My code returns a matrix that still contains (!) some duplicated columns. Any help?
Tags (comma-separated)
Save Edits
Cancel