【发布时间】:2015-04-05 17:22:49
【问题描述】:
您可以使用以下命令轻松地在 R 控制台中以文本形式打印出 rpart 树结果。
fit <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis)
print(fit)
然后打印出来:
n=81
node), split, n, loss, yval, (yprob) * 表示终端节点
1) 根 81 17 缺席 (0.79012346 0.20987654) 2) 开始>=8.5 62 6 缺席 (0.90322581 0.09677419)
4) 开始>=14.5 29 0 缺席 (1.00000000 0.00000000) * 5) 开始 10) 年龄=55 21 6 缺席 (0.71428571 0.28571429)
22) 年龄>=111 14 2 缺席 (0.85714286 0.14285714) * 23) 年龄
但是,这在 Rshiny textOutput 中不起作用。
请参阅以下 Rshiny 代码:
ui.r
library(shiny)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
# Application title
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot"),
textOutput("distText")
)
)
)
服务器.r
library(shiny)
library(rpart)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
output$distText <- renderText({
fit <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis)
print(fit)
})
})
如果我运行上述闪亮的应用程序,它会给出以下错误:
cat(list(...)、file、sep、fill、labels、append) 中的错误:
'cat' 无法处理参数 1(类型 'list')
【问题讨论】: