为什么字段分隔符只能是一个字节? [英] Why the field separator character must be only one byte?

查看:151
本文介绍了为什么字段分隔符只能是一个字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

data <- read.delim("C:\\test.txt", header = FALSE, sep = "$$$$$")
Error in scan(file, what = "", sep = sep, quote = quote, nlines = 1, quiet = TRUE,  : 
  invalid 'sep' value: must be one byte

为什么会有这样的限制?我可以克服吗?

Why there is a restriction like this? Can I overcome it?

推荐答案

这是一个潜在的解决方案。

Here is a potential solution.

假设文件中的行是这样的

Assuming this is what the lines in your file look like

1 $$$$$ 2 $$$$$ 3 $$$$$ 4

下面将创建一个变量并将其存储为字符的矩阵。

The following will create a matrix with the variables stored as characters.

do.call(rbind,strsplit(readLines('test.txt'),'$$$$$',fixed=T))

这篇关于为什么字段分隔符只能是一个字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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