[R] Return filematrix column by column names instead of column index?

nevil amos nev||@@mo@ @end|ng |rom gm@||@com
Tue Sep 8 13:37:44 CEST 2020


Is there a way to get columns out of a filematrix using the column name
directly in the same way that  you can with a regular matrix?

library(filematrix)
M<-t(matrix(1:3,3,4))
colnames(M)<-c("one","two", "three")
M
#Extract column
M[,1]
M[,"one"]
M[,c(1,3)]
M[,c("one","three")]
FM<-fm.create.from.matrix(filenamebase = "test",mat = M)
FM[,1]
colnames(FM)
#extract by column by name does not work
FM[,"one"]

#workaround using grep
#is there a more direct way of doing this  to retrieve more than one column?
FM[,grep("one",colnames(FM))]

FM[,c(grep("one",colnames(FM)),grep("three",colnames(FM)))]

many thanks for any suggestions

Nevil Amos

	[[alternative HTML version deleted]]



More information about the R-help mailing list