我想要做的是为比例的上下置信区间设置列。
这是我所做的:
> #Create some sample data
> Frustration <- data.table(group = c('A','B','C'), trials = c(363,1398,139), surg = c(57,276,18))
> Frustration
group trials surg
1: A 363 57
2: B 1398 276
3: C 139 18
>
> #try to get confidence levels. what I am expecting is CI to be a list of 2 elements, for each value of group, but I don't think that is working
> F2 <- Frustration[, .(CI = prop.test(surg, trials, conf.level = .75)['conf.int']), by = .(group)]
> F2
group CI
1: A 0.1350140,0.1816828
2: B 0.1851178,0.2103210
3: C 0.09701967,0.16972056
>
> #lower is still a list here - I am stumped
> F3 <- F2[, .(lower = CI[[1]]), by = .(group)]
> F3
group lower
1: A 0.1350140,0.1816828
2: B 0.1851178,0.2103210
3: C 0.09701967,0.16972056
我认为我的困惑与列表有关,以及数据表如何处理返回值。
谢谢你的帮助,
David
transpose
。 - r2evansF2$CI
,它是一个list
列,每个列表元素中有两个元素。data.table::transpose(F2$CI)
通过将列表的每个对应元素连接成一个向量来改变list
的长度,即每个列表元素的第一个元素由单个向量组成,同样地,第二个元素即下限和上限组件被重新分组为新列表中的两个向量。 - akrun