Re: [问题] if elso loop不能接着执行?

楼主: nh2 (nh)   2014-11-02 22:42:24
※ 引述《Edster (Edster)》之铭言:
: best <- function(x, y){
: z <- c("heart attack", "heart failure", "pneumonia")
: outcome <- read.csv(file="outcome-of-care-measures.csv", header=T, as.is=T)
: SS <- as.numeric(outcome[,11])
: if (! (x %in% outcome$State) | ! (y %in% z)){
: stop("Error in best(state, outcome) : invalid state")
: }
: if (y == "heart attack"){
: select = outcome$State == x & !is.na(SS); o = order(SS)
: result <- outcome[o[select],c(1,2)]
: print(paste("best (", result, ") heart attack"))
: }
: }
请问从倒数第三行(select = outcome$State....)之后,
为何我用
o <- order(SS[select])
outcome.order <- outcome[o, ]
结果outcome.order还是有NA值存在?
作者: Edster (Edster)   2014-11-04 23:26:00
看来问题出现在order. 那么就得要老老实实的把order 跟 is.na 分开了.outcome = outcome[order(as.numeric(outcome[,11])),]select = outcome$State == x & !is.na((as.numeric(outcome[,11]))result <- outcome[select,c(1,2)]变得有点丑... 现下也想不到更好的方式.

Links booklink

Contact Us: admin [ a t ] ucptt.com