Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6731693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:33:34+00:00 2026-05-26T10:33:34+00:00

I can use read.csv or read.csv2 to read data into R. But the issue

  • 0

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 with this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:33:34+00:00Added an answer on May 26, 2026 at 10:33 am

    Providing example data would help. However, you might be able to adapt the following to your needs.

    I created an example data file, which is a just a text file containing the following:

    1sep2sep3
    1sep2sep3
    1sep2sep3
    1sep2sep3
    1sep2sep3
    1sep2sep3
    1sep2sep3
    

    I saved it as ‘test.csv’. The separation character is the ‘sep’ string. I think read.csv() uses scan(), which only accepts a single character for sep. To get around it, consider the following:

    dat <- readLines('test.csv')
    dat <- gsub("sep", " ", dat)
    dat <- textConnection(dat)
    dat <- read.table(dat)
    

    readLines() just reads the lines in. gsub substitutes the multi-character seperation string for a single ' ', or whatever is convenient for your data. Then textConnection() and read.data() reads everything back in conveniently. For smaller datasets, this should be fine. If you have very large data, consider preprocessing with something like AWK to substitute the multi-character separation string. The above is from http://tolstoy.newcastle.edu.au/R/e4/help/08/04/9296.html .

    Update
    Regarding your comment, if you have spaces in your data, use a different replacement separator. Consider changing test.csv to :

    1sep2 2sep3
    1sep2 2sep3
    1sep2 2sep3
    1sep2 2sep3
    1sep2 2sep3
    1sep2 2sep3
    1sep2 2sep3 
    

    Then, with the following function:

    readMulti <- function(x, sep, replace, as.is = T)
    {
        dat <- readLines(x)
        dat <- gsub(sep, replace, dat)
        dat <- textConnection(dat)
        dat <- read.table(dat, sep = replace, as.is = as.is)
    
        return(dat)
    }
    

    Try:

    readMulti('test.csv', sep = "sep", replace = "\t", as.is = T)
    

    Here, you replace the original separator with tabs (\t). The as.is is passed to read.table() to prevent strings being read in is factors, but that’s your call. If you have more complicated white space within your data, you might find the quote argument in read.table() helpful, or pre-process with AWK, perl, etc.

    Something similar with crippledlambda’s strsplit() is most likely equivalent for moderately sized data. If performance becomes an issue, try both and see which works for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want simultaneously read and write data into file. Can i use StreamReader and
Using EF we can use LINQ to read data which is rather simple (especially
Can anyone recommend a simple API that will allow me to use read a
I want to read the html file.And for that I use System.IO.File.ReadAllText(path) .It can
I read about ContactsContract.CommonDataKinds.GroupMembership , but I can't figure out what URI use to
I'm trying to read into R a csv file that contains information on political
Is there a standard Linux command i can use to read a file chunk
If I have an xmlreader instance how can I use it to read its
How can i use opendir function to read the directory list of a remote
In C++ I Can Read The MAC Address Of The NIC and Use It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.