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 8934147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:42:56+00:00 2026-06-15T09:42:56+00:00

I have a file that has 22268 rows BY 2521 columns. When I try

  • 0

I have a file that has 22268 rows BY 2521 columns. When I try to read in the file using this line of code:

file <- read.table(textfile, skip=2, header=TRUE, sep="\t", fill=TRUE, blank.lines.skip=FALSE)

But I only get 13024 rows BY 2521 columns read in and the following error:

Warning message: In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : number of items read is not a multiple of the number of columns

I also used this command to see what rows had an incorrect number of columns:

x <-count.fields(textfile, sep="\t", skip=2)
incorrect <- which(x != 2521)

and got back a list of about 20 rows that were incorrect.

Is there a way to fill these rows with NA values?

I thought that is what the “fill” parameter does in the read.table function, but it doesn’t appear so.

OR

Is there a way to ignore these rows that are identified in the “incorrect” variable?

  • 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-06-15T09:42:56+00:00Added an answer on June 15, 2026 at 9:42 am

    you can use readLines() to input the data, then find the offending rows.

        con <- file("path/to/file.csv", "rb")
        rawContent <- readLines(con) # empty
        close(con)  # close the connection to the file, to keep things tidy
    

    then take a look at rawContent

    To find the rows with an incorrect number of columns, for example:

        expectedColumns <- 2521
        delim <- "\t"
    
        indxToOffenders <-
        sapply(rawContent, function(x)   # for each line in rawContent
            length(gregexpr(delim, x)[[1]]) != expectedColumns   # count the number of delims and compare that number to expectedColumns
        ) 
    

    Then to read in your data:

      myDataFrame <- read.csv(rawContent[-indxToOffenders], header=??, sep=delim)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file that has a line of code like this: $var =
I have a file that has columns that look like this: Column1,Column2,Column3,Column4,Column5,Column6 1,2,3,4,5,6 1,2,3,4,5,6
I have the file that has content like this per line 3021e69d9d2569db27ce7b74ccaa98496007de09a1f4b94e45f48203d8727ac6 test.com [05/Jul/2011:07:28:57
I have a test file that has many lines, each line looks something like:
I have a text file that has item numbers in it (one per line).
I have a file that has 2 columns as given below.... 101 6 102
I have a file that has two columns of floating point values. I also
I have a file that has > 10 rows. I want to create 9
I have a file that has many xml-like elements such as this one: <document
I have a text file that has strings on each line. I want to

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.