Hi all.. I am doing an survival analysis, and the code works fine in RStudio, but when copying it into Quarto, I get the following error message:
"Quitting from lines 480-491 [quartiles] (report.qmd)
Error in cut.default()
:
! 'x' must be numeric
Backtrace:
- base::cut(...)
- base::cut.default(...)
Execution halted
The code is as follows:
data$quartiles <- cut(data$mean_treatment_time_hours,
breaks = quantile(data$mean_treatment_time_hours,
probs = c(0, 1/4, 2/4, 3/4, 1), na.rm = TRUE),
labels = c("Quartile 1", "Quartile 2", "Quartile 3", "Quartile 4"),
include.lowest = TRUE)
quartilenames <- c("Quartile 1", "Quartile 2", "Quartile 3", "Quartile 4")
data$quartiles.fac <- factor(x = data$quartiles, levels = quartilenames, ordered = TRUE)
When I check class(data$mean_treatment_time_hours)
- the console returns numeric....
Any ideas? Thanks in advance, Jim
FJCC
2
Did you run class(data$mean_treatment_time_hours)
in your Quarto document or in your local RStudio environment? Try it in the document.
Thanks... I get this:
Warning: Unknown or uninitialised column: `mean_treatment_time_hours`.
[1] "NULL"
Which is odd as I've been using the same variable previously for tables, plots etc!
FJCC
5
You should be able to use the same class() call in earlier parts of your code to find where you lose the mean_treatment_hours column.
cderv
6
@jimmy_squids if you still have issue, can you share more about your document and formatted correctly ? FAQ: How to Format R Markdown Source
system
Closed
7
This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.