简体   繁体   English

r中横向合并两行单行数据

[英]Combine two single rows of data horizontally in r

I'm new to R so this probably has a simple solution, but I can't find it.我是 R 的新手,所以这可能有一个简单的解决方案,但我找不到。 I have two datasets:我有两个数据集:

Dataset 1:数据集 1:

A一个 B C C
1 1 2 2 3 3

Dataset 2:数据集 2:

X X Y Z Z
4 4 5 5 6 6

and I want to get我想得到

A一个 B C C X X Y Z Z
1 1 2 2 3 3 4 4 5 5 6 6

The dataset is just one row each.每个数据集只有一行。

Just use cbind :只需使用cbind

cbind(dataset1, dataset2)

For your next questions, please create reproducible examples using dput for example.对于您的下一个问题,请使用dput创建可重现的示例。 Posting data in the form of images or tables isn't very useful.以图像或表格的形式发布数据并不是很有用。

You can use CTRL+K to format text as code sample when writing a question on SO.在 SO 上写问题时,您可以使用CTRL+K将文本格式化为代码示例。

You could also use the merge() function:您也可以使用merge() function:

merge(x, y, by = intersect(names(x), names(y)),
  by.x = by, by.y = by,
  sort = TRUE, …)

This would be more useful when you are combining more complex data.frames but it can be useful to learn it early.当您组合更复杂的 data.frames 时,这会更有用,但尽早学习它会很有用。

You can look and see how it works in more details as follows;您可以查看并查看它的工作原理,如下所示; ?merge

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM