-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.

2
  • 1
    myMat[, names] should do it. whether it is a matrix or a data.frame. Commented Jul 3, 2017 at 13:18
  • Regarding edit: no need to put tag in the title, and "thank you" is a noise. Commented Jul 3, 2017 at 13:22

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.