1

Suppose I have x like this

              [,1]     [,2]     [,3]     [,4]     [,5]     [,6]     [,7]
rs1952251 12.05886 23.72529 30.92366 37.53577 43.64377 46.75088 48.93301
rs3009943 11.90153 22.70790 30.29965 32.53084 34.70415 36.29477 37.77274

I would like to extract first row and make that as a 1 by 7 matrix. I use x[1,]. But I got

> x[1,]
[1] 12.05886 23.72529 30.92366 37.53577 43.64377 46.75088 48.93301

It is a vector and it does not have rownames. I would like to get something as following:

              [,1]     [,2]     [,3]     [,4]     [,5]     [,6]     [,7]
rs1952251 12.05886 23.72529 30.92366 37.53577 43.64377 46.75088 48.93301
Mike Brown
  • 331
  • 2
  • 12
  • 1
    Can't find a dup here but - http://r.789695.n4.nabble.com/how-to-keep-row-name-if-there-is-only-one-row-selected-from-a-data-frame-td895594.html – thelatemail Jul 14 '16 at 01:17
  • @alistaire - I think that's close enough - swtiching row to column is essentially identical. – thelatemail Jul 14 '16 at 01:21

1 Answers1

2

You could try converting to a data frame before you take the subset:

data.frame(x)[1,]
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360