Note that there are some explanatory texts on larger screens.

plurals
  1. POData type issue, integer data into R from csv
    primarykey
    data
    text
    <p>I have a data.frame in R which has been constructed off the Example 1-3 dataset here: <a href="http://riskfactor.cancer.gov/diet/usualintakes/dataset.html" rel="nofollow">http://riskfactor.cancer.gov/diet/usualintakes/dataset.html</a></p> <p>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: </p> <pre><code>t_0104nc &lt;- read.csv("foo.csv",header=T) </code></pre> <p>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.</p> <p>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.</p> <p>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.</p> <p>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.</p> <p>Update from the suggestions below. All I need is a simple boolean true/false test, so I have used:</p> <p><code>if(isTRUE(all.equal(x, xi &lt;- as.integer(x)))) y="TRUE" else y="FALSE"</code></p> <p><code>y</code></p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload