Text 为什么字段分隔符只能是一个字节? 数据

Text 为什么字段分隔符只能是一个字节? 数据,text,r,delimiter,Text,R,Delimiter,这里有一个潜在的解决方案 假设文件中的行是这样的 1$$$2$$3$$4 下面将创建一个矩阵,其中变量存储为字符 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 by

这里有一个潜在的解决方案

假设文件中的行是这样的

1$$$2$$3$$4

下面将创建一个矩阵,其中变量存储为字符

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

如果您希望最终结果是数据帧,则可以使用
类型转换字符矩阵。convert
,请参阅
do.call(rbind,strsplit(readLines('test.txt'),'$$$$$',fixed=T))