-3

i get this output using coxme model. i'm trying to work with this part, the frailty/RE output, which looks like this.

>fitpm50$frail$'ST_BASELINE/CMSA_MSA'
CA/680       CA/2840       CA/4472       CA/6922       CA/7120       CA/7320  
1.129591e-02 1.208329e-02 -3.709842e-02  2.353560e-02 -3.345176e-04  1.359872e-02  

I would like to sort this and output this as a data frame. The tricky part here is that I want to sort by the number, removing the CA/. I came up with this:

>sort(as.character(substring(attributes(fitpm50$frail$'ST_BASELINE/CMSA_MSA')$names, 4, 7)

which sort of works, but this returns that 680 is the third biggest value, whereas I want it so that 680 is the smallest. Also this just returns sorted values for the headers, whereas I want the whole output sorted as a data frame.

Thanks

user2543095
  • 107
  • 8

1 Answers1

0

You are sorting on character strings, not numbers. If you want to sort by numeric values, then you need to convert to numbers.

Rgames> foo<-c('680','780','1290','450','1100')
Rgames> sort(as.numeric(foo))
[1]  450  680  780 1100 1290
Carl Witthoft
  • 20,573
  • 9
  • 43
  • 73