R按位置

时间:2016-11-15 18:22:27

标签: r list dataframe merge position

1)正确合并两个listst of data.frame: 我希望按位置合并两个数据帧列表(在每个数据帧中)(位于一个列表中的第一个数据帧和另一个列表的第一个数据帧,第二个数据帧与第二个数据帧合并...第53个带有第53届)。 例如列表 输入

    [[1]]$`16-09-26`
  total price qnty     code     date   REFERENCE
  1011   51.9  17.3    3    45917 16-09-26 RefProd0168
  1012 118.44  4.23   28    42442 16-09-26 RefProd0103
  1013  21.28  5.32    4 14758353 16-09-26 RefProd0263
  1014  10.64  5.32    2 14758360 16-09-26 RefProd0102
  1023  68.16  4.26   16  4127329 16-09-26 RefProd0145

STR(inputbydate) 清单2

$       :List of 54
..$ 15-08-03:'data.frame':  14 obs. of  6 variables:
.. ..$ total    : Factor w/ 137 levels "","/","101.52",..: 80 117 20 
.. ..$ price    : Factor w/ 49 levels "","10.16","10.38",..: 48 26 29 29 
.. ..$ qnty     : num [1:14] 4 16 3 2 6 4 12 4 16 3 ...
.. ..$ code     : Factor w/ 54 levels "","14458956",..: 21 38 5 6 8 27 28 
.. ..$ date     : Date[1:14], format: "15-08-03" "15-08-03" "15-08-03" ...
.. ..$ REFERENCE: Factor w/ 50 levels "","REFERENCE",..: 9 6 19 5 15 21 8 

(...)

输入inputbydate,例如

      Names = c("total", "price", "qnty", "code", "date", "REFERENCE"), row.names = c(741L, 742L, 743L, 748L, 750L), class = "data.frame"), `16-05-30` = structure(list(total = structure(c(75L, 3L, 64L, 39L, 95L), .Label =c("","/", "101.52", "105.57",..., "price"), class = "factor")qnty = c(3, 24, 6, 4, 12), code = structure(c(22L, 38L, 5L, 6L, 28L), .Label = c("", "14458956", "code"), class = "factor"), date = structure(c(-713534, -713534, -713534, -713534, -713534), class = "Date"), REFERENCE = structure(c(30L, 6L, 19L, 5L, 8L), .Label = c("", "REFERENCE", "RefProd0064", "RefProd0088",...,, class = "factor"))

第二个列表

   $purchase52
       V9 V12
1 RefProd0103  10
2 RefProd0145   4 
3 RefProd0152   5
4 RefProd0224   2
5 RefProd0642   1

$purchase53
           V9 V12
1 RefProd0102   4
2 RefProd0103  11
3 RefProd0145   9
4 RefProd0152   3
5 RefProd0224   2
6 RefProd0263   5
7 RefProd0642   7

    purchase38:'data.frame':    6 obs. of  2 variables:
    ..$ V9 : Factor w/ 1430 levels "","RefProd","RefProd0001",..: 104 105 147 154 226 265
    ..$ V12: num [1:6] 2 16 8 4 5 2
      $ purchase39:'data.frame':    7 obs. of  2 variables:
    ..$ V9 : Factor w/ 1430 levels "","RefProd","RefProd0001",..: 104 105     147 154 226 265 644
    ..$ V12: num [1:7] 1 20 8 6 1.27 5 1

e.g。 dput购买

  Names = c("V9", "V12"), row.names = c(NA, -5L), class = "data.frame")), .Names = c("purchase01","purchase02", "purchase03",...,"purchase54"))

我必须通过"参考"合并列表=" V9" 。来自输入日期列表和V9的参考资料来自购买清单。

2)差异问题,如何独立地在每个数据框中进行计算。之后,我必须使用" qnty" " V12"区别。

3)Biuld a dinamic table :最后,按日期(数据框)取这个值并制作一个完整的表,其中包含第一列的所有RefProd值和逐月的差异。

我尝试使用

llply(inputbydate,function(x){do.call(as.data.frame, lapply(inputbydate, "[[",1)),x=})

mapply(merge, inputbydate,purchase,by.x="REFERENCE", by.y = "V9", SIMPLIFY = FALSE)

do.call,join,merge_all ...

似乎输入列表是数据帧列表的列表。也许它让我有问题...如果我能在列表中提取列表,也许它会帮助我。

任何帮助都将具有重要价值

0 个答案:

没有答案