在R中写入csv文件时的定界符 [英] Delimiters while writing csv files in R

查看:198
本文介绍了在R中写入csv文件时的定界符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在R中写入csv文件时,如何使用|(管道)作为定界符?

How can I use |(pipe) as a delimiter while writing csv files in R?

当我尝试使用write.csvsep = "|"将数据集写入文件时,它会忽略分隔符并将其简单地以逗号分隔的文件形式写入.

When I try writing a data set into a file with write.csv with sep = "|", it ignores the separator and writes the file simply as a comma separated file.

而且write.csv2似乎也没有涵盖可用作分隔符的其他各种字符.

Also write.csv2 also doesn't seem to cover the other variety of characters which could be used as a separator.

在用R编写csv文件时,是否可以使用其他字符(例如^,$,〜,¬或|)作为定界符.

Is there a way to use other characters such as ^, $, ~, ¬ or |, as a delimiter while writing a csv file in R.

谢谢.

推荐答案

您必须了解.csv表示逗号分隔的值"

You have to understand that .csv means "comma-separated value" https://en.wikipedia.org/wiki/Comma-separated_values.

如果要使用使用该字符的分隔符导出,则需要另一个功能.

If you want to export with a separator using that characters you need another function.

例如,使用write.table,您将能够使用RExcel,....

For example, using write.table, and you'll be able to load this file with R, Excel,....

write.table(data, "data.txt", sep = "|")
data_load <- read.table("data.txt", sep = "|")

随意使用任何字符作为分隔符.

Feel free to use any character as separator.

或者您也可以将此纯文本强制为.csv

Or you could force this plain text to be .csv

write.table(data, "data.csv", sep = "|")
data_load <- read.csv("data.csv", sep = "|")

这篇关于在R中写入csv文件时的定界符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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