r - R编程 - 顺序函数无法与包含一位和两位数字变量的列正确工作
问题描述
因此,我尝试使用 order 函数为我提供一个按最佳函数中所需结果变量排序的数据框。如果结果列中只有两位数,则 order 和 best 函数似乎都可以正常工作。
该列应从 8.1 到 15.8 排序,但结果最终是从 10.0 到 15.8 和 8.1 到 10.0
best <- function(state, outcome){
setwd('C:/users/nikumar/datasciencecoursera')
ocm <- read.csv('outcome-of-care-measures.csv', colClasses = 'character', na.strings = "Not Available", stringsAsFactors = FALSE)
index <- numeric()
if ((state %in% ocm$State) == FALSE) {
stop("invalid state")
}
if (outcome == 'heart attack') {
index <- 11
}
else if (outcome == 'heart failure' ) {
index <- 17
}
else if (outcome == 'pneumonia') {
index <- 23
}
else{
stop("invalid outcome")
}
ocm1 <- ocm[ocm$State == state,]
ocm1 <- ocm1[,c(2,7,index)]
ocm1 <- ocm1[order(ocm1[3],ocm1[1], decreasing = FALSE),]
ocm1 <- na.omit(ocm1)
View(ocm1)
ocm1[1,1]
}
解决方案
推荐阅读
- internet-explorer-11 - DataStudio 图表在 Internet Explorer 11 中的初始页面加载失败
- javascript - 增加对 map function() 和语法的理解
- audio - 使用 FFmpeg 或类似软件将视频中的音频标准化为 EBU R128 标准
- javascript - 我收到“不变违规”错误的渲染方法做错了什么?
- kotlin - 检查对象的类是否继承自特定的密封类
- java - 本地应用程序和 Jenkins 部署之间的 Java 日期时间不一致
- redux - Vuex 选择器,如 redux 重新选择
- python - 如何加快 python lxml 中的 xbrl 文件解析?
- sql - 如何删除 SQL Server 自联接中的重复行
- c# - 使用 AWS C# 中托管的 .net 核心的 Windows 服务等效项