-1

One list of names:

names = c(col1, col2, col6)

matrix like this:

col1 col2 col3 col4 col5 col6
  1    4    5    2    7    2
  4    5    7    2    8    1

in order to have this:

col1 col2 col6
  1    4    2
  4    5    1

select "names" from "matrix" to create a new matrix.

zx8754
  • 46,390
  • 10
  • 104
  • 180
F.Lira
  • 633
  • 1
  • 6
  • 15

1 Answers1

0

You need to put your names in quotes, then...

names = c("col1", "col2", "col6")
m2 <- m[,names]

m2
     col1 col2 col6
[1,]    1    4    2
[2,]    4    5    1
Andrew Gustar
  • 15,825
  • 18
  • 28