添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

I'm new to R and learning it via Coursera and during one of the assignments outline in this pdf I encountered the following error:

Error in split.default(x = seq_len(nrow(x)), f = f, drop = drop, ...) :   
group length is 0 but data length > 0

Basically I'm stuck in part 2 Finding best Hospital in the state part, and while writing function for it I test its constructs via console. So far to test it I wrote this piece of code:

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

I'm also attaching the Hospital Sample

Hope anyone can point me in the right direction.

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

you named it state, and then tried to split on a column called State. R is case sensitive.