楼主: 最强壹号
1148 2

[问答] r语言小白求助 [推广有奖]

  • 0关注
  • 0粉丝

小学生

64%

还不是VIP/贵宾

-

威望
0
论坛币
2 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
50 点
帖子
1
精华
0
在线时间
15 小时
注册时间
2018-11-11
最后登录
2020-6-13

楼主
最强壹号 发表于 2018-11-11 14:03:01 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
------------------------------------------------------------------------代码
rankhospital <- function(state, outcome, num = "best") {
        ## Read outcome data
        data <- read.csv("outcome-of-care-measures.csv")
        ## Check that state and outcome are valid
        state_flags<-FALSE
        states<-levels(data[,7])[data[,7]]
        for (i in 1:length(states)) {
                if (state==states) {
                        state_flags<-TRUE
                }
        }
        if (!state_flags) {
                stop("invalid state")

        }
        if (!((outcome == "heart attack") | (outcome == "heart failure")
              | (outcome == "pneumonia"))) {
                stop("invalid outcome")

        }
        col <- if (outcome == "heart attack") {
                11
        } else if (outcome == "heart failure") {
                17
        } else {
                23
        }
        data[, 2] <- as.character(data[, 2])
        statedata <- data[grep(state, data$State), ]
        orderdata <- statedata[order(statedata[, col], statedata[, 2], na.last = NA), ]
        if(num == "best") {
                orderdata[1, 2]
        } else if(num == "worst") {
                orderdata[nrow(orderdata), 2]
        } else{
                orderdata[num, 2]
        }
        ## Return hospital name in that state with the given rank
        ## 30-day death rate
-----------------------------------------------------------------分割结束
为什么标红的类型转化语句存在与不存在会导致输出不同的结果呢,因为这个数据原本类型就是字符,为什么还需要转换类型?有大腿能帮忙答疑么?

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:R语言 Rank HOS RAN

沙发
啊啊啊啊啊吖 发表于 2018-12-4 18:50:55
帮你顶帖~~~~

藤椅
啊啊啊啊啊吖 发表于 2018-12-4 18:57:40
expr       
The name of a function, or a call or an expression written as a function of x which will evaluate to an object of the same length as x.
x       
a ‘vectorizing’ numeric R function.
y       
alias for from for compatibility with plot
from, to       
the range over which the function will be plotted.
n       
integer; the number of x values at which to evaluate.
add       
logical; if TRUE add to an already existing plot; if NA start a new plot taking the defaults for the limits and log-scaling of the x-axis from the previous plot. Taken as FALSE (with a warning if a different value is supplied) if no graphics device is open.
xlim       
NULL or a numeric vector of length 2; if non-NULL it provides the defaults for c(from, to) and, unless add = TRUE, selects the x-limits of the plot – see plot.window.
type       
plot type: see plot.default.
xname       
character string giving the name to be used for the x axis.
xlab, ylab, log, ...       
labels and graphical parameters can also be specified as arguments. See ‘Details’ for the interpretation of the default for log.
For the "function" method of plot, ... can include any of the other arguments of curve, except expr.

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-9 09:48