【发布时间】:2020-02-13 15:22:11
【问题描述】:
我有一个名为 G 的 data.frames 列表。
在 BASE R 中,我想知道如何分别提取 AA 和 BB 中的元素 dint 和 SD
data.frame colnames 包含 short del1 和 del2(请参阅下面的我的所需输出) ?
G <- list(AA = list(short = data.frame(dint = 5:7, SD = 0:2), short..2 = NULL, del1 = data.frame(dint = 1:3, SD = 2:4),
del1..2 = NULL, del2 = NULL),
BB = list(short = data.frame(dint = 1:4, SD = 2:5), short..2 = NULL, del1 =
data.frame(dint = 5:6, SD = 3:4), del1..2 = NULL, del2 = data.frame(dint = 6, SD = 1)) )
我想要的输出是:
# dints:
dints = list(
short = list(AA = c(short = 5:7), BB = c(short = 1:4)),
del1 = list(AA = c(del1 = 1:3), BB = c(del1 = 5:6)),
del2 = list(AA = c(del2 = NULL), BB = c(del2 = 6)))
# SDs:
SDs = list(
short = list(AA = c(short = 0:2), BB = c(short = 2:5)),
del1 = list(AA = c(del1 = 2:4), BB = c(del1 = 3:4)),
del2 = list(AA = c(del2 = NULL), BB = c(del2 = 1)))
【问题讨论】:
标签: r list function loops dataframe