后续:从R?中的data.frames列表中提取?

时间:2019-10-16 21:29:04

标签: r list function loops dataframe

this question的后续工作:我有一个名为G的数据帧列表。

在BASE R中,我想知道如何分别提取元素dintSD中的元素AABB data.frame同名的基本名称short del1del2(请参阅我的 所需输出 >下面)?

注意: HERE提供的解决方案忽略了后缀名,例如short..3等。

G <- list(AA = list(short..3 = 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..4 = 
                 data.frame(dint = 5:6, SD = 3:4), del1..2 = NULL, del2 = data.frame(dint = 6, SD = 1)) )

我想要的输出是(我希望内部名称(例如,“ short”不自动后缀):

# 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)))

0 个答案:

没有答案