R Reorder matrix columns by matching colnames to list of string

前端 未结 1 1369
迷失自我
迷失自我 2021-01-04 20:00

Sorry if this is very basic. I have a list of names and a matrix with those names as column names. However, the colnames are in a different order.

Eg. List of name

相关标签:
1条回答
  • 2021-01-04 20:43

    You just have to use a vector for the names and the [-operator as follows:

    col.order <- c("colname4","colname3","colname2","colname5","colname1")
    M[,col.order]
    
    0 讨论(0)
提交回复
热议问题