如何在R中写入一个csv文件,其中我的输入作为行写入文件中? [英] How do I write a csv file in R, where my input is written to the file as row?

查看:162
本文介绍了如何在R中写入一个csv文件,其中我的输入作为行写入文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常简单的问题,令我惊讶的是,没有在线示例.

This is a very simple issue and I'm surprised that there are no examples online.

我有一个向量:

vector <- c(1,1,1,1,1)

我想将其作为csv编写为一个简单的行:

I would like to write this as a csv as a simple row:

write.csv(vector, file ="myfile.csv", row.names=FALSE)

当我打开刚写的文件时,csv被写为一列值. 好像R决定在每个数字1之后插入换行符.

When I open up the file I've just written, the csv is written as a column of values. It's as if R decided to put in newlines after each number 1.

请原谅我是无知的人,但是我一直认为使用逗号分隔值的目的是要表达从左到右的值,并以逗号分隔.就像我刚刚做的那样;在某种意义上模仿了书面语的语法.当csv显然应该是行时,为什么R如此拼命地坚持列格式?

Forgive me for being ignorant, but I always assumed that the point of having comma-separated-values was to express a sequence from left to right, of values, separated by commas. Sort of like I just did; in a sense mimicking the syntax of written word. Why does R cling so desperately to the column format when a csv so clearly should be a row?

除所有语言哲学外,我还尝试使用移调功能.我已经翻阅了文档.请帮忙!谢谢.

All linguistic philosophy aside, I have tried to use the transpose function. I've dug through the documentation. Please help! Thanks.

推荐答案

紧跟@Matt所说的内容,如果要使用csv,请尝试eol=",".

Following up on what @Matt said, if you want a csv, try eol=",".

这篇关于如何在R中写入一个csv文件,其中我的输入作为行写入文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆