0

I have a matrix,and i need to generate column name to the matrix. column names should be something like this.

"out01"  "out02"  "out03"  "out04" ... to .. "out30"

This is what i have tried

outmat <- matrix(NA, 5, 30)
colnames(outmat) <- sprintf("out%d", 1:30)

generated column names are like this.

 "out1"  "out2"  "out3"  "out4"  "out5"  "out6"  "out7"  "out8"  "out9"  "out10" .... to "out30"

is there any direct way to covert out1 to out01 in sprintf method.

Rajith Thennakoon
  • 3,975
  • 2
  • 14
  • 24

1 Answers1

5

Yes, specify %02d

sprintf("out%02d", 1:30)
#[1] "out01" "out02" "out03" "out04" "out05" "out06" "out07" "out08" "out09"....
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213