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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:57:13+00:00 2026-05-26T17:57:13+00:00

I have a data.frame in R which has been constructed off the Example 1-3

  • 0

I have a data.frame in R which has been constructed off the Example 1-3 dataset here:
http://riskfactor.cancer.gov/diet/usualintakes/dataset.html

I converted it from SAS to ASCII using Stat Transfer, saving as a csv. I have imported the data into R using the read.csv command:

t_0104nc <- read.csv("foo.csv",header=T)

The data are in data.frame structure. Within this file are some columns that relate to weights (RNDW through RNDW32). While these appear to be integers, when looking at the data in Excel, the cells have General format. R has brought the data in as double.

I’m using RNDW1, and I need to confirm that it is integer. However, entering typeof(RNDW1) and storage.mode(RNDW1) both show the data as double.

What is the most efficient way for me to test that I only have integer values in that column? I don’t want to coerce the data, as the existence of non-integers would indicate a fundamental problem with the data that coercing won’t fix.

Alternatively, I was wondering if there was some way of importing the data so it stored as the simplest data type in R – which should then import these values as integer. Some of the data is integer, other data is single or double, so the data is not all the same type.

Update from the suggestions below. All I need is a simple boolean true/false test, so I have used:

if(isTRUE(all.equal(x, xi <- as.integer(x)))) y="TRUE" else y="FALSE"

y

Which then returns me a single true or false value to indicate the overall result of the test. I appreciate all the (rapid!) help I received, and I am happy with the code and my understanding of it.

  • 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-26T17:57:13+00:00Added an answer on May 26, 2026 at 5:57 pm

    all.equal provides one way to test if all of the values in a column are integer valued.

    Here’s a function that might do what you like:

    careful.as.integer <- function(x) {
        if(!is.numeric(x)) return(x) # For factor, character, and logical vectors 
        if(all.equal(x, as.integer(x))== TRUE) {
              as.integer(x)
         } else {
              x
         }
    }
    
    DAT <- data.frame(a = c(NA, 1:3), 
                      b = c(1:2, 3.3, NA), 
                      species = c("cat", "dog", "goat", "okapi"))
    
    data.frame(lapply(DAT, careful.as.integer))
    #    a   b species
    # 1 NA 1.0     cat
    # 2  1 2.0     dog
    # 3  2 3.3    goat
    # 4  3  NA   okapi
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SQLDF newbie here. I have a data frame which has about 15,000 rows and
I have a data.frame which has multiple columns. One of the columns is time
I have a data.frame called series_to_plot.df which I created by combining a number of
I have a data frame where one particular column has a set of specific
I have a data frame in R that has come about from running some
I have a binary file, inside of which has multiple frames. Each frame starts
I have a file, called genes.txt , which I'd like to become a data.frame.
I have an app which has to load some data at startup, so I
I currently have a dataset which has two columns that I'd like to compare.
I have the following question: I have data frame which looks like this. I

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.