[英]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.