R中每行的Running ageadjust.indirect
我在像地理区域这样的普查区域使用ageadjust.indirect。 我有两个数据框用于地理数据<代码>案例和R中每行的Running ageadjust.indirect,r,R,我在像地理区域这样的普查区域使用ageadjust.indirect。 我有两个数据框用于地理数据案例和pop。 我还有两个用于标准总体和标准病例计数的向量标准POP和标准CNT分别。5个年龄组的长度为5 包含区域数据(cases和pop)的数据框均为671行,各有5列(针对5个年龄组) 我想运行ageadjust.indirect()来获得每个区域的年龄调整率,我使用这段代码来尝试实现这一点: ageadjust.indirect(cases, pop, stdcount = standard
pop
。
我还有两个用于标准总体和标准病例计数的向量<代码>标准POP和标准CNT
分别。5个年龄组的长度为5
包含区域数据(cases
和pop
)的数据框均为671行,各有5列(针对5个年龄组)
我想运行ageadjust.indirect()
来获得每个区域的年龄调整率,我使用这段代码来尝试实现这一点:
ageadjust.indirect(cases, pop, stdcount = standardcnt, stdpop = standardpop)
但是,这只返回一个调整后的速率,同时返回所有观察到的情况
如何对
案例和pop
的每一行运行ageadjust.indirect(),以获得每个地理单位的调整率?一个选项可能是循环其中一个数据的行序列(因为两者具有相同的维度),并对数据集子集应用该函数
out <- lapply(seq_len(nrow(cases)), function(i)
ageadjust.indirect(cases[i,], pop[i,],
stdcount = standardcnt, stdpop = standardpop))
@akrun是的,我使用总年龄分布作为标准POP,总病例分布作为标准CNT。第一个建议满足了我的要求!我只需要一些后处理,因为ageadjust函数输出两个数据帧的列表。
library(magrittr)
library(purrr)
list(cases, pop) %>%
pmap(~ ageadjust.indirect(count = ..1,
pop = ..2,
stdcount = standardcnt,
stdpop = standardpop))