0
median(classifyforblack$Survival.months[classifyforblack$newcolumn == 'GU'])
[1] NA

Warning message: In mean.default(sort(x, partial = half + 0L:1L)[half + 0L:1L]) : argument is not numeric or logical: returning NA

I need to calculate median survival months when the value is GU but it give this error. I think that is because some values in survival months are"unknown" how to overcome that?

  • Hi there and welcome to SO. Please give us some context to your question. Take a look at [How to Ask](https://stackoverflow.com/help/how-to-ask) for hints. It's a good start to give some data, make a [great reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and give an example of your desired output. – Martin Gal Sep 01 '21 at 21:49
  • We need to see your data, to give you an answer. Most likely `Survival.months` doesn't contain numeric values. Besides "unknown" what are the other values auf `Survival.months`? – Martin Gal Sep 01 '21 at 21:54
  • As per the error message `Survival.months` is "not numeric or logical". – kangaroo_cliff Sep 01 '21 at 22:28
  • My best guess: (1) Replace "unknown" by `NA`. (2) Convert `Survival.months` into a numeric vector using `as.double` or `as.integer`. (3) Use the `na.rm = TRUE` argument of `mean()`. – Martin Gal Sep 01 '21 at 22:34

0 Answers0