-1

I'm looking to define the header column from table S2 as the information in Row1_Row2.

I can currently set a column header from row 1 or R2 using the line below:

R> colnames(S2) <- S2[1,]

but I've been unable to find a way to include both R1 and R2 in the header.

Any help would be great!

Jautis
  • 459
  • 6
  • 13
  • It would help to have a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with a sample `S2` object so we know exactly what we're working with. – MrFlick Sep 03 '14 at 19:17

1 Answers1

0

I'm guessing you mean something like this

S2 <- matrix(letters[1:15], nrow=3)
S2
#      [,1] [,2] [,3] [,4] [,5]
# [1,] "a"  "d"  "g"  "j"  "m" 
# [2,] "b"  "e"  "h"  "k"  "n" 
# [3,] "c"  "f"  "i"  "l"  "o" 

colnames(S2) <- paste(S2[1,], S2[2,], sep="_")
S2
#      a_b d_e g_h j_k m_n
# [1,] "a" "d" "g" "j" "m"
# [2,] "b" "e" "h" "k" "n"
# [3,] "c" "f" "i" "l" "o"
MrFlick
  • 195,160
  • 17
  • 277
  • 295