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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:09:35+00:00 2026-06-17T19:09:35+00:00

Apologies as I thought there would be a very obvious answer but I can’t

  • 0

Apologies as I thought there would be a very obvious answer but I can’t find anything on the net…

I often get very large datasets where missing values are blank e.g. (in short)

#Some description of the dataset
#cover x number of lines
31   3213 313   64    63
31   3213 313   64    63
31   3213 313   64    63
31   3213 313   64    63
31   3213 313   64    63
12   178        190   865
532  31   6164  68
614       131   864   808

I would like to replace all the blanks by, for example, -999. If I use read table such that

dat = read.table('file.txt',skip=2)

I get the error message

Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
line 6 did not have 5 elements

I could open the file as a data frame and do

dat = data.frame('file.txt',skip=2)
is.na(rad1) = which(rad1 == '')

but I don’t know if it would work because I don’t know how to skip the top 2 lines when reading a dataframe (e.g. the equivalent of “skip”) and I couldn’t find the answer either anywhere. Could anyone help?

Thanks.

  • 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-17T19:09:37+00:00Added an answer on June 17, 2026 at 7:09 pm

    If you know the widths of each column then you can use read.fwf

    e.g.

    > dat <- read.fwf('temp.txt', skip=2, widths=c(5,5,6,6,6))
    > dat
       V1   V2   V3  V4  V5
    1  31 3213  313  64  63
    2  31 3213  313  64  63
    3  31 3213  313  64  63
    4  31 3213  313  64  63
    5  31 3213  313  64  63
    6  12  178   NA 190 865
    7 532   31 6164  68  NA
    8 614   NA  131 864 808
    

    Although it’s easy to replace NA values with any value you want, that’s just a bad idea, because R has many great way of dealing with NA values.

    For example, to take the mean of column two, use:

    mean(dat$V2, na.rm=TRUE)
    [1] 163.4286
    

    R has other functions to deal with missing data. For example, you can use na.omit() to completely remove rows with missing data.

    > na.omit(dat)
      V1   V2  V3 V4 V5
    1 31 3213 313 64 63
    2 31 3213 313 64 63
    3 31 3213 313 64 63
    4 31 3213 313 64 63
    5 31 3213 313 64 63
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies if there answer is already out there, but I could not find it.
So, I searched some here, but couldn't find anything good, apologies if my search-fu
Apologies for asking what's probably a very obvious question, I've been banging my head
Please excuse me if there are already answers to this, but I can't quite
I did a number of searches, but couldn't find an answer to this question.
Apologies if this is a slightly noob question, but looking to clarify my thoughts
Apologies if this is answered elsewhere; couldn't find enough information to convince myself of
Apologies if this is a repost, I could not find the search terms to
Apologies, I can only include 2 URLs as a new user so I have
I'm new to iPhone development, so apologies if this is a silly question, but

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.