我已设法subset
和lapply
数据框列表如下:
subsetDeathHA <-
na.omit(subset(outcome,select = c("Hospital Name", "mortailityRate", "State"), ))
orderSubsetDeathHA <-
subsetDeathHA[order(subsetDeathHA$"mr" , subsetDeathHA$"Hospital Name", subsetDeathHA$'State' ),]
splitOrderSubsetDeahtHA <-
split(orderSubsetDeathHA, orderSubsetDeathHA$'State')
aa<- lapply(splitOrderSubsetDeahtHA, function(x) { x[num,] })
num
是每个州的排名。
使用str(aa)
显示此对象是(54)data.frame
s的列表,其中每个data.frame
是3个变量的一个对象,如下所示:
List of 54
$ AK:'data.frame': 1 obs. of 3 variables:
..$ Hospital Name : chr NA
..$ mortalityRate : num NA
..$ State : chr NA
..- attr(*, "na.action")=Class 'omit' Named int [1:1986] 4 5 6 10 13 17 19 23 27 28 ...
.. .. ..- attr(*, "names")= chr [1:1986] "4" "5" "6" "10" ...
$ AL:'data.frame': 1 obs. of 3 variables:
..$ Hospital Name : chr "D C H REGIONAL MEDICAL CENTER"
..$ mortalityRate : num 15.8
..$ State : chr "AL"
..- attr(*, "na.action")=Class 'omit' Named int [1:1986] 4 5 6 10 13 17 19 23 27 28 ...
.. .. ..- attr(*, "names")= chr [1:1986] "4" "5" "6" "10" ...
我似乎无法做到以下
1)通过移除Hospital Name
变量来设置State
和mortalityRate
,并返回生成的54个对象/数据框的列表。
2)适当放置row.names =F
以抑制R提供的索引。
3)尽管我以为自己已经“出去了”。第一个子设置操作中的NA
值,
当我print(aa)
时,接下来是输出的样本。
$AK
Hospital Name mr State
NA NA <NA> NA <NA>
$AL
Hospital Name mr State
56 D C H REGIONAL MEDICAL CENTER 15.8 AL
等...
任何帮助/建议赞赏