【问题标题】:Getting this error with split function in R [closed]在 R 中使用拆分功能出现此错误 [关闭]
【发布时间】:2017-06-14 23:11:07
【问题描述】:

我是 R 新手,通过 Coursera 学习它,在 this pdf 的其中一项作业大纲中遇到以下错误:

Error in split.default(x = seq_len(nrow(x)), f = f, drop = drop, ...) :   

group length is 0 but data length > 0

基本上我被困在第 2 部分找到州内最好的医院部分,并且在为它编写函数时,我通过控制台测试它的构造。到目前为止,为了测试它,我写了这段代码:

outcome <- read.csv("outcome-of-care-measures.csv", colClasses = "character")
outcome[, 11] <- as.numeric(outcome[, 11]) # 30-day mortality for the heart attack
outcome[, 17] <- as.numeric(outcome[, 17]) # 30-day mortality for the heart failure 
outcome[, 23] <- as.numeric(outcome[, 23]) # 30-day mortality for the pneumonia 
outcome <- outcome[, c(2, 7, 11)] # Subsetting three columns
outcome <- na.omit(outcome) # omitting na
names(outcome) <- c("hospital", "state", "outcome") #Renaming the columns
outcome <- split(outcome, outcome$State) # Splitting it based on states

我还附上了Hospital Sample

希望任何人都可以为我指明正确的方向。

【问题讨论】:

    标签: r split subset


    【解决方案1】:

    应该是state,而不是State。看数据:

    > head(outcome)
                              hospital state outcome
    1 SOUTHEAST ALABAMA MEDICAL CENTER    AL    14.3
    2    MARSHALL MEDICAL CENTER SOUTH    AL    18.5
    3   ELIZA COFFEE MEMORIAL HOSPITAL    AL    18.1
    

    您将其命名为 state,然后尝试在名为 State 的列上进行拆分。 R 区分大小写。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-19
      • 1970-01-01
      • 1970-01-01
      • 2021-04-14
      • 2019-12-31
      • 1970-01-01
      • 2018-07-15
      • 1970-01-01
      相关资源
      最近更新 更多