[英]R: Write data to a particular column in csv file
I have 2 functions, func1 and func2 whose job is to aggregate data from other input files, load them into data frames(df1, df2) separately and write to a single csv file. 我有2个函数,func1和func2,它们的工作是聚合来自其他输入文件的数据,分别将它们加载到数据帧(df1,df2)中并写入单个csv文件。 I am trying to get df1 and df2 to load different columns in the same csv file.
我试图让df1和df2在同一csv文件中加载不同的列。 Is this possible?
这可能吗?
Sample Data: 样本数据:
Output.CSV: 输出.CSV:
Name Age Sex Salary Deductions
Mike 50 M 50000 0
Molly 61 F 65000 500
Jake 22 M 28000 0
df1 loads Name Age and Sex columns. df1加载“名称年龄”和“性别”列。 I want df2 to load the Salary and Deductions columns.
我希望df2加载“薪金和扣除额”列。 In a nut shell, I basically am looking at an update(in RDBMS jargon) option where once df1 has loaded the first 3 columns, df2 should be able to update the other 2.
简而言之,我基本上是在看一个update(在RDBMS行话中)选项,其中df1加载了前3列后,df2应该能够更新其他2列。
I'll appreciate any help or guidance. 我将不胜感激任何帮助或指导。 Thanks.
谢谢。
您可以在write.csv
之前使用cbind
df1
和df2
:
write.csv(cbind(df1,df2),"your csv path")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.