-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
  • 52,746
  • 12
  • 114
  • 209
F.Lira
  • 663
  • 2
  • 6
  • 19

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
  • 17,295
  • 1
  • 22
  • 32