r - R中不同长度向量的组合
问题描述
我有两个邮政编码向量(站点和客户)。我试图找到两个向量之间的对组合。
因此,如果网站的大小为 3,而客户的大小为 4……我希望有 12 种组合。我目前正在使用 cross() 在 R 中执行此操作。
但是,当我放入大小为 20 和客户大小为 6057 的实际数据站点时,该函数返回 35,760 个组合,而我期望有 121,140 (6057*20) 个组合。这是否意味着有很多重复的组合并且它们被删除了?
我的代码复制如下。提前致谢。
data <- read_xlsx("Sites.xlsx", sheet = "Sheet3")
data2 <- read_xlsx("Customers.xlsx", sheet = "Sheet1")
sites <- as.vector(data['FRT - Ship From Zip'])
sites
Customers <- as.vector(data2['Ship_To_Zip'])
Customers
Comdata <- crossing(Customers,sites)
Customers <- as.vector(Comdata['Ship_To_Zip'])
sites <- as.vector(Comdata['FRT - Ship From Zip'])
解决方案
基础 R 解决方案:
expand.grid(x, y)
# Data
x <- 1:20
y <- 1:6057
推荐阅读
- blazor - 如何从 BLAZOR 的客户端层调用服务器层中的方法
- javascript - How can style the element that I bold in JavaScript?
- docker - Dockerfile 运行管道 powershell
- android - 录制视频时背景音频播放 - Flutter
- php - 联系表单验证以防止空白电子邮件
- python - 在 MYSQL 中未正确识别不同的术语
- ubuntu - 如何在 Linux 中使用命令 systemctl restart elasticsearch?
- oracle - 哪个 Oracle 版本最适合 Windows 10 以及如何在 Oracle Sql Developer 中检查数据库连接
- flutter - 检查用户是否第一次使用 bloc 进行身份验证
- teradata - 如何在 Tera 数据中设置 parquet 文件的大小,使其超过 16 MB?