【发布时间】:2014-07-18 21:35:03
【问题描述】:
我正在尝试重塑具有这种结构的销售 data.frame
categorization_one gender created_at fk_id_customer_info CONCAT_gender_cat_one
1 Toys Feminino 13/11/2013 04:54 1 ToysFemale
2 Toys Masculino 13/11/2013 04:54 2 Toys Male
3 Computers Masculino 14/11/2013 04:54 2 Toys Male
我想做一个 excel 数据透视表,其中行是 categorization_one 字段,列是字段 CONCAT_gender_cat_one 内的值。此表中的值将是 categorization_one 和 CONCAT_gender_cat_one 的交集之间的计数。 我正在尝试使用以下代码使用 reshape 包来做到这一点:
cast(compras.parte.1,fk_id_customer_info ~ categorization_one, count, margins = TRUE)
但是我收到了这个错误:
incorrect number of dimensions
编辑,这是来自以下结果的复制/粘贴:dput(droplevels(head(compras.parte.1)))
structure(list(categorization_one = structure(c(4L, 2L, 3L, 2L,
1L, 5L), .Label = c("Bebês/Alimentação/Mamadeiras", "Brinquedos/Desenhos e Pintura",
"Brinquedos/Games e Eletrônicos/Laptops, Tablets e Cia", "Brinquedos/Primeira Infância",
"Calçados/Sapatilhas"), class = "factor"), gender = structure(c(1L,
2L, 2L, 2L, 3L, 1L), .Label = c("Feminino", "Masculino", "Masculino/Feminino"
), class = "factor"), created_at = structure(c(1L, 1L, 1L, 1L,
1L, 1L), .Label = "13/11/2013 04:54", class = "factor"), fk_id_customer_info = structure(c(1L,
2L, 2L, 2L, 3L, 1L), .Label = c("2", "3", "5"), class = "factor"),
GENDER_PESQUISA = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = "não respondeu", class = "factor"),
cat_one_gender = structure(c(4L, 2L, 3L, 2L, 1L, 5L), .Label = c("Bebês/Alimentação/MamadeirasMasculino/Feminino",
"Brinquedos/Desenhos e PinturaMasculino", "Brinquedos/Games e Eletrônicos/Laptops, Tablets e CiaMasculino",
"Brinquedos/Primeira InfânciaFeminino", "Calçados/SapatilhasFeminino"
), class = "factor")), .Names = c("categorization_one", "gender",
"created_at", "fk_id_customer_info", "GENDER_PESQUISA", "cat_one_gender"
), row.names = c(NA, 6L), class = "data.frame")
【问题讨论】:
-
这看起来不像
dput(),看起来只是head() -
@MrFlick 哦好的,dput() 输出所有因子,但是这里无法打印,因为 fk_id_customer_info 有 100k 个因子(每个客户 1 个)
-
@user3511563,然后可能是
dput(droplevels(head(compras.parte.1)))? -
@MrFlick 我用 Ananda 的建议更新了我的问题。