简体   繁体   English

如何通过加入列将 2 个 CSV 文件合并为一个

[英]How to combine 2 CSV files into one by joining columns

file1.csv文件1.csv

name,surname
tom,brown
aaron,brown
jon,doe

file2.csv文件2.csv

age
22
24
26

I want an output to be a file result.csv with the following content:我希望输出是具有以下内容的文件 result.csv:

name,surname,age
tom,brown,22
aaron,brown,24
jon,doe,26

You should be able to do cbind, as suggested in the comments.您应该能够按照评论中的建议执行 cbind。

df1= read.csv("file1.csv", header=T)
df2= read.csv("file2.csv", header=T)
df= cbind(df1, df2)
write.csv(df, "file.csv)

They just have to be the same length.它们的长度必须相同。 Add NAs if you need to.如果需要,请添加 NA。

暂无
暂无

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

相关问题 将一些csv文件合并为一个不同数量的列 - Combine some csv files into one - different number of columns 将csv文件合并为1个不同列的文件 - Combine csv files into 1 with different columns 如何将几个类似的.csv文件组合成一个给定结构的数据帧 - How to combine several similar .csv files into one dataframe with given structure R - 如何在不重载 memory 的情况下将 many.csv 文件合并为一个? - R - How to combine many .csv files into one without overloading memory? 如何将两列合并到由两个或多个不同的csv文件组成的数据帧中的新列中? - How do you combine two columns into a new column in a dataframe made of two or more different csv files? 如何在R中合并多个.csv文件? - How to combine multiple .csv files in R? 如何将多个csv文件合并为一个大文件而不将实际文件加载到环境中? - How to combine multiple csv files into one big file without loading the actual file into the environment? 如何通过使用R将每个文件的数据添加为附加行来将不同的.csv文件组合为一个完整文件? - How to combine different .csv files to one complete file by adding the data of every file as an additional row using R? 将100个CSV文件与标题合并为一个的最快方法是什么? - What is the fastest way to combine 100 CSV files with headers into one? 读取多个ENVI文件并将它们组合在一个csv中 - read multiple ENVI files and combine them in one csv
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM