subset in dcast cannot find function "." # reshape2 #dcast

Hi i used dcast to manipulate dataframe

newmd<- dcast(data = 全产品销售团队预进生量 ,

          formula = products + managers~ date,
 
          subset=.(date < "202301"),         # it noticed me that it cannot find the function "."
                                                                              i library reshape2 again, but it did not work.
                                                                              what should i do?
          fun.aggregate = sum,
          
          value.var = "生效量")

Can you post a subset of your data? Use the dput() function to do that. If your data frame is named DF, post the output of

dput(head(DF, 20))

Put a line with three back ticks just before and after the output, like this:
```
output of dput() goes here
```
It might avoid problems if the column names used only Latin characters

1 Like

dput(head(全产品销售团队预进生量, 20))
structure(list(产品名称 = c("23Q2思享驾租赁新车产品-低首付1",
"23Q2思享驾租赁新车产品-常规首付H1", "23Q2思享驾租赁新车产品-常规首付HH1",
"23Q2思享驾租赁新车产品-常规首付HH1", "23Q2思享驾租赁新车产品-常规首付HHH1",
"23Q2思享驾租赁新车产品-常规首付HHH1", "23Q2思享驾租赁新车产品-常规首付HHH1",
"23Q3思享驾租赁新车产品-常规首付HH1", "23Q3思享驾租赁新车产品-常规首付HH1",
"23Q3思享驾租赁新车产品-常规首付HHH1", "23Q3思享驾租赁新车产品-常规首付HHH1",
"23Q3思享驾租赁新车产品-常规首付HHH1", "23Q3思享驾租赁标准二手车产品-常规首付1",
"23Q3思享驾租赁标准二手车产品-常规首付1", "23Q3思享驾租赁认证二手车产品-常规1",
"23Q3思享驾租赁认证二手车产品-常规1", "23Q3思享驾租赁认证二手车产品-常规1",
"一汽丰田0息", "一汽丰田低利率高返佣产品", "一汽丰田低利率高返佣产品"
), 日期 = c("202305", "202304", "202304", "202306", "202304",
"202305", "202306", "202307", "202308", "202307", "202308", "202309",
"202308", "202309", "202307", "202308", "202309", "202209", "202112",
"202112"), 金融经理 = c("罗鸣健", "罗鸣健", "罗鸣健",
"罗鸣健", "邓翘", "邓翘", "邓翘", "罗鸣健", "罗鸣健",
"邓翘", "邓翘", "邓翘", "罗鸣健", "罗鸣健", "罗鸣健",
"罗鸣健", "罗鸣健", "罗鸣健", "罗鸣健", "郑君"),
预审量 = c(1, 1, 3, 1, 1, 1, 3, 2, 5, 1, 3, 1, 1, 3, 1,
2, 1, 1, 5, 1), 进件单量 = c(1, 0, 3, 2, 1, 1, 3, 1,
5, 1, 3, 1, 2, 3, 1, 2, 1, 0, 5, 0), 生效量 = c(1, 0,
2, 2, 1, 1, 2, 1, 2, 1, 3, 1, 1, 2, 1, 0, 0, 0, 1, 0), 生效金额 = c(31.2,
0, 39.96, 51.83, 20, 22.96, 45.96, 22.5, 35.2, 17.8, 61.8,
35, 12, 35, 10, 0, 0, 0, 27.6179, 0)), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -20L), groups = structure(list(
产品名称 = c("23Q2思享驾租赁新车产品-低首付1",
"23Q2思享驾租赁新车产品-常规首付H1", "23Q2思享驾租赁新车产品-常规首付HH1",
"23Q2思享驾租赁新车产品-常规首付HH1", "23Q2思享驾租赁新车产品-常规首付HHH1",
"23Q2思享驾租赁新车产品-常规首付HHH1", "23Q2思享驾租赁新车产品-常规首付HHH1",
"23Q3思享驾租赁新车产品-常规首付HH1", "23Q3思享驾租赁新车产品-常规首付HH1",
"23Q3思享驾租赁新车产品-常规首付HHH1", "23Q3思享驾租赁新车产品-常规首付HHH1",
"23Q3思享驾租赁新车产品-常规首付HHH1", "23Q3思享驾租赁标准二手车产品-常规首付1",
"23Q3思享驾租赁标准二手车产品-常规首付1",
"23Q3思享驾租赁认证二手车产品-常规1", "23Q3思享驾租赁认证二手车产品-常规1",
"23Q3思享驾租赁认证二手车产品-常规1", "一汽丰田0息",
"一汽丰田低利率高返佣产品"), 日期 = c("202305",
"202304", "202304", "202306", "202304", "202305", "202306",
"202307", "202308", "202307", "202308", "202309", "202308",
"202309", "202307", "202308", "202309", "202209", "202112"
), .rows = structure(list(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19:20), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -19L), .drop = TRUE))

I put it on my console, and the outcome is here.
my concern is that
subset=.(date > "202301" & managers == "邓翘")
does work previously, but yesterday R noticed" could not find function "."

You need to load the package {plyr}:

全产品销售团队预进生量 <- structure(list(...))



library(plyr)
newmd<- reshape2::dcast(data = 全产品销售团队预进生量 ,
                        formula = 产品名称 + 金融经理 ~ 日期,
                        subset=.(日期 < "202301"),
                        fun.aggregate = sum,
                        value.var = "生效量")
newmd
#>                   产品名称 金融经理 202112 202209
#> 1              一汽丰田0息   罗鸣健      0      0
#> 2 一汽丰田低利率高返佣产品   罗鸣健      1      0
#> 3 一汽丰田低利率高返佣产品     郑君      0      0

Created on 2023-09-21 with reprex v2.0.2

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.