Previous: Standard Ways to Load Up: Loading Data Next: Verifying You Loaded The

Special Cases When Loading Data

These procedures apply to any of the above read commands:

  1. If your file uses the first row to identify variable names, you should use the option header = TRUE to import those field names. For example,
      
    > read.csv("mydata.csv", header = TRUE)
    
    will read the words in the first row as the variable names and the subsequent rows (each with the same number of values as the first) as observations for each of those variables. If you have additional characters on the last line of the file or fewer values in one of the rows, you need to edit the file before attempting to read the data.
  2. The R missing value code is NA. If this value is in your data, R will recognize your missing values as such. If you have instead used a place-holder value (such as -9) to represent missing data, you need to tell R this on loading the data:
    > read.table("mydata.tab", header = TRUE, na.strings = "-9")
    
    Note: You must enclose your place holder values in quotes.
  3. Unlike Windows, the file extension in R does not determine the default method for dealing with the file. For example, if your data is tab-delimited, but saved as a .sav file, read.table("mydata.sav") will load your data into R.



Gary King 2011-11-29