r - Merge two tables with no relation on columns
问题描述
I would like to merge two tables that has no relations on columns.
This are the examples:
Table A:
Table B:
The idea is to merge the tables, creating a row for each row that are in both tables, and assigning 'NA' to the column that we don't have information. This would be the result example:
I have tried with merge() but in this case I just get one row (with the values) instead of two.
The idea is to merge two tables with a lot of columns and a lot of rows, how can I do this?
解决方案
df.1[, colnames(df.2)] <- NA
df.2[, colnames(df.1)[1:2]] <- NA
rbind(df.1, df.2)
Gender Age Id Group 1 0 27 NA NA 2 NA NA 1 0
样本数据
df.1 <- data.frame(Gender = 0, Age = 27)
df.2 <- data.frame(Id = 1, Group = 0)
推荐阅读
- php - 从 facebook API 获取所有潜在客户广告
- c - 运算符关联性,优先级
- java - 如何使我的 if 条件在 Java 的线程中工作?
- html - 如何更改平板电脑布局上的 Bootstrap 3 列布局?
- python-3.x - 如何在 pywebview/eel 中从一个窗口启动操作并在另一个窗口执行操作?
- powershell - Powershell Active Directory 用户名
- amazon-web-services - Terraform:如何使用键值输出
- python-3.x - 如何在我的熊猫数据框中填充前一天的非空值
- c# - c# 无法从简单数组中设置变量
- python - 如何在 python SQLAlchemy 中按子字符串排序