I can use read.csv or read.csv2 to read data into R. But the issue I encountered is that my separator is a multiple-byte string instead of a single character. How can I deal
In this case you can replace textConnection(txt) with your file name, but essentially you can build a code or function around strsplit. Here I'm assuming you have a header line, but you can of course give define a header argument and generalize the creation of your data frame based on the function below:
read.multisep <- function(File,sep) {
Lines <- readLines(File)
Matrix <- do.call(rbind,strsplit(Lines, sep, fixed = TRUE))
DataFrame <- structure(data.frame(Matrix[-1,]), names=Matrix[1,]) ## assuming header is present
DataFrame[] <- lapply(DataFrame, type.convert) ## automatically convert modes
DataFrame
}
example <- "a#*&b#*&c
1#*&2#*&3
4#*&5#*&6"
read.multisep(textConnection(example),sep="#*&")
a b c
1 1 2 3
2 4 5 6